Fix a bug where album art and track info could get out of sync if you advance twice quickly

This commit is contained in:
James Babcock committed 2026-10-13 16:17:07 -07:00
1 parent eb91d46657
commit 13da595de0
6 files changed
+38 -13

No files matched your search

@@ -46,6 +46,7 @@ class FaceclawMediaController(context: Context) {
override fun onMetadataChanged(metadata: MediaMetadata?) {
synchronized(lock) {
artVersion++
emitStateLocked()
}
}
@@ -92,6 +93,15 @@ class FaceclawMediaController(context: Context) {
private var sessionsListenerRegistered = false
private var ignoredPackages: Set<String> = HashSet()
/**
* Bumped whenever the art getAlbumArtGray would return may have changed:
* every metadata update and every switch of active session. Players
* re-publish the same title/album with a different bitmap (art attached
* after download, or a stale bitmap from the previous track replaced
* after a quick double skip), so the strings can't key an art cache.
*/
private var artVersion = 0
init {
this.listenerComponent = ComponentName(appContext, FaceclawMediaNotificationListenerService::class.java)
this.sessionManager = appContext.getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager?
@@ -404,6 +414,7 @@ class FaceclawMediaController(context: Context) {
previous.unregisterCallback(controllerCallback)
}
activeController = controller
artVersion++
if (controller != null) {
controller.registerCallback(controllerCallback, mainHandler)
}
@@ -503,6 +514,7 @@ class FaceclawMediaController(context: Context) {
val finalCanSkipPrevious = canSkipPrevious
val finalAccessEnabled = accessEnabled
val finalStatus = status
val finalArtVersion = artVersion
mainHandler.post {
currentListener.onStateChange(
@@ -519,7 +531,8 @@ class FaceclawMediaController(context: Context) {
finalCanSkipNext,
finalCanSkipPrevious,
finalAccessEnabled,
finalStatus
finalStatus,
finalArtVersion
)
}
}