Fixed album art image is not clear enough and always shows the previous song's cover in Android 13 (test device: Sony Xperia 1 IV)

This commit is contained in:
michaellee123 2022-12-26 15:34:55 +08:00
parent e6267ef6a2
commit 4ce212a6e6

View file

@ -23,6 +23,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.content.pm.ServiceInfo import android.content.pm.ServiceInfo
import android.database.ContentObserver import android.database.ContentObserver
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.media.AudioManager import android.media.AudioManager
import android.os.* import android.os.*
@ -1021,7 +1022,7 @@ class MusicService : MediaBrowserServiceCompat(),
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null)
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, playingQueue.size.toLong()) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, playingQueue.size.toLong())
if (isAlbumArtOnLockScreen) { if (isAlbumArtOnLockScreen || VERSION.SDK_INT == 33) {
// val screenSize: Point = RetroUtil.getScreenSize(this) // val screenSize: Point = RetroUtil.getScreenSize(this)
val request = GlideApp.with(this) val request = GlideApp.with(this)
.asBitmap() .asBitmap()
@ -1036,6 +1037,13 @@ class MusicService : MediaBrowserServiceCompat(),
CustomTarget<Bitmap?>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) { CustomTarget<Bitmap?>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
override fun onLoadFailed(errorDrawable: Drawable?) { override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable) super.onLoadFailed(errorDrawable)
metaData.putBitmap(
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
BitmapFactory.decodeResource(
resources,
R.drawable.default_audio_art
)
)
mediaSession?.setMetadata(metaData.build()) mediaSession?.setMetadata(metaData.build())
onCompletion() onCompletion()
} }