diff --git a/app/build.gradle b/app/build.gradle index 7e6623fe3..29a6be8c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,7 +136,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - def kotlin_coroutines_version = '1.6.1' + def kotlin_coroutines_version = '1.6.2' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version" diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt index 5add7c79a..54d470bdd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.kt @@ -171,7 +171,7 @@ class MusicService : MediaBrowserServiceCompat(), @JvmField var playingQueue = ArrayList() - private var playerHandler: Handler? = null + private var playerHandler: Handler? = null private var playingNotification: PlayingNotification? = null @@ -633,7 +633,7 @@ class MusicService : MediaBrowserServiceCompat(), restorePlaybackState(wasPlaying, progress) } } - ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData() + ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData(::updateMediaSessionPlaybackState) COLORED_NOTIFICATION -> { playingNotification?.updateMetadata(currentSong) { playingNotification?.setPlaying(isPlaying) @@ -775,14 +775,14 @@ class MusicService : MediaBrowserServiceCompat(), @Synchronized fun play() { - playbackManager.play(onNotInitialized = { playSongAt(getPosition()) }) { - if (notHandledMetaChangedForCurrentTrack) { - handleChangeInternal(META_CHANGED) - notHandledMetaChangedForCurrentTrack = false - } + playbackManager.play(onNotInitialized = { playSongAt(getPosition()) }) { + if (notHandledMetaChangedForCurrentTrack) { + handleChangeInternal(META_CHANGED) + notHandledMetaChangedForCurrentTrack = false } - notifyChange(PLAY_STATE_CHANGED) } + notifyChange(PLAY_STATE_CHANGED) + } fun playNextSong(force: Boolean) { playSongAt(getNextPosition(force)) @@ -1006,7 +1006,7 @@ class MusicService : MediaBrowserServiceCompat(), } @SuppressLint("CheckResult") - fun updateMediaSessionMetaData() { + fun updateMediaSessionMetaData(onCompletion: () -> Unit) { Log.i(TAG, "onResourceReady: ") val song = currentSong if (song.id == -1L) { @@ -1036,32 +1036,31 @@ class MusicService : MediaBrowserServiceCompat(), if (isBlurredAlbumArt) { request.transform(BlurTransformation.Builder(this@MusicService).build()) } - runOnUiThread { - request.into(object : - CustomTarget(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) { - override fun onLoadFailed(errorDrawable: Drawable?) { - super.onLoadFailed(errorDrawable) - mediaSession?.setMetadata(metaData.build()) - } + request.into(object : + CustomTarget(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) { + override fun onLoadFailed(errorDrawable: Drawable?) { + super.onLoadFailed(errorDrawable) + mediaSession?.setMetadata(metaData.build()) + onCompletion() + } - override fun onResourceReady( - resource: Bitmap, - transition: Transition?, - ) { - metaData.putBitmap( - MediaMetadataCompat.METADATA_KEY_ALBUM_ART, - copy(resource) - ) - mediaSession?.setMetadata(metaData.build()) - } + override fun onResourceReady( + resource: Bitmap, + transition: Transition?, + ) { + metaData.putBitmap( + MediaMetadataCompat.METADATA_KEY_ALBUM_ART, + resource + ) + mediaSession?.setMetadata(metaData.build()) + onCompletion() + } - override fun onLoadCleared(placeholder: Drawable?) { - mediaSession?.setMetadata(metaData.build()) - } - }) - } + override fun onLoadCleared(placeholder: Drawable?) {} + }) } else { mediaSession?.setMetadata(metaData.build()) + onCompletion() } } @@ -1090,8 +1089,9 @@ class MusicService : MediaBrowserServiceCompat(), startForegroundOrNotify() } - updateMediaSessionMetaData() - updateMediaSessionPlaybackState() + // We must call updateMediaSessionPlaybackState after the load of album art is completed + // if we are loading it or it won't be updated in the notification + updateMediaSessionMetaData(::updateMediaSessionPlaybackState) serviceScope.launch(IO) { savePosition() savePositionInTrack() @@ -1107,7 +1107,7 @@ class MusicService : MediaBrowserServiceCompat(), QUEUE_CHANGED -> { mediaSession?.setQueueTitle(getString(R.string.now_playing_queue)) mediaSession?.setQueue(playingQueue.toMediaSessionQueue()) - updateMediaSessionMetaData() // because playing queue size might have changed + updateMediaSessionMetaData(::updateMediaSessionPlaybackState) // because playing queue size might have changed saveState() if (playingQueue.size > 0) { prepareNext() diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt index e3752aa16..24726bbe5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt @@ -24,7 +24,6 @@ import android.graphics.BitmapFactory import android.graphics.drawable.Drawable import android.support.v4.media.session.MediaSessionCompat import androidx.core.app.NotificationCompat -import androidx.core.text.parseAsHtml import androidx.media.app.NotificationCompat.MediaStyle import code.name.monkey.appthemehelper.util.VersionUtils import code.name.monkey.retromusic.R @@ -111,9 +110,9 @@ class PlayingNotificationImpl24( } override fun updateMetadata(song: Song, onUpdate: () -> Unit) { - setContentTitle(("" + song.title + "").parseAsHtml()) + setContentTitle(song.title) setContentText(song.artistName) - setSubText(("" + song.albumName + "").parseAsHtml()) + setSubText(song.albumName) val bigNotificationImageSize = context.resources .getDimensionPixelSize(R.dimen.notification_big_image_size) GlideApp.with(context)