PlayerNotificationManager not updating on fast consecutive actions
See original GitHub issue[REQUIRED] Issue description
I’m using ExoPlayer to play some HLS tracks. When i’m doing couple of fast actions (like tap 3-4 times Next button) by mediaController
or in notification - the content i return in PlayerNotificationManager.MediaDescriptionAdapter
doesn’t get displayed. Notification displays one track previous to the one that is actually playing. So Changing playback this way properly updates the player state, but doesn’t seem to update the notification properly. I can’t seem to make some 100% repro, but it does this consistently when i smash next/previous button quite fast.
[REQUIRED] Reproduction steps
This is my MediaDescriptionAdapter
:
internal class MediaDescriptionAdapter(
private val context: Context,
private val sessionPendingIntent: PendingIntent?
) : PlayerNotificationManager.MediaDescriptionAdapter {
private var currentBitmap: Bitmap? = null
override fun createCurrentContentIntent(player: Player?): PendingIntent? = sessionPendingIntent
override fun getCurrentContentText(player: Player?): String? = player?.let {
val mediaDescription = it.currentTag as MediaDescriptionCompat? ?: return ""
mediaDescription.subtitle.toString()
}
override fun getCurrentContentTitle(player: Player?): String {
player?.let {
val mediaDescription = it.currentTag as MediaDescriptionCompat? ?: return ""
Timber.d("getCurrentContentTitle with ${mediaDescription.title.toString()}")
return mediaDescription.title.toString()
}
return ""
}
override fun getCurrentLargeIcon(
player: Player?,
callback: PlayerNotificationManager.BitmapCallback?
): Bitmap? {
val mediaDescription = player?.currentTag as MediaDescriptionCompat?
val uri = mediaDescription?.iconUri ?: return null
Glide
.with(context)
.asBitmap()
.load(uri)
.into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
// Nothing to do here
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
callback?.onBitmap(resource)
currentBitmap = resource
}
})
return currentBitmap
}
}
As you can see i log the result of getCurrentContentTitle
. I can confirm that this method gets called properly and i do return correct metadata for currently playing track. So it seems like notification don’t get some kind of update event properly.
Can you think of any reason this could be happening?
My first idea was that Glide callback could brake something, but when i return null on every getCurrentLargeIcon
the problem still occurs.
#EDIT: i think i have some repro. When i change the track, wait for the time it takes to load hls and click next and the exact time - notification doesn’t get refreshed but track is changed
#EDIT2: Sometimes metadata is updated properly, but notification background isn’t set when callingcallback.onBitmap()
.
[REQUIRED] Link to test content
This bug seems to be unrelated to any particular content
[REQUIRED] Version of ExoPlayer being used
2.10.7
[REQUIRED] Device(s) and version(s) of Android being used
Multiple emulators, from android 6 to 10, OnePlus 7 with Android 10
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (6 by maintainers)
Top GitHub Comments
This has now been done in Marc’s change ref’d above. @marcbaechinger - Should we either close this or reclassify it as a platform bug at this point?
I was able to reproduce this with Google Play Music, Spotify and the ExoPlayer demo app using the PlayerNotificationManager:
For the case when I just hit the play/pause button repeatedly the notification is updated once for each status update (in this case playWhenReady true/false). When hitting very quickly I can still go over the enqueue rate threshold which causes the notification to be out of sync.
So reducing the notification updates alone will make it harder for users to produce this (needs hitting faster), but it is still possible. I’m looking into providing a fix for this.
A second approach might be to somehow throttle updates of the notifications. I’m not sure what is the best way of doing this as I actually don’t want to significantly increase the lag between the command arriving and the update of the notification.
I’ll update this thread when we push something to the dev-v2 branch.