You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Media Notification does not update content title on API Level > 29 #219
start playing a MediaItem with alternating MediaMetadata
observe MediaNotification
Expected result
Notification represents the current MediaMetadata:
content title to metadata title
content text to metadata artists
Actual result
Notification doesn't represent the current MediaMetadata only the content text is changing accordingly, the title is stuck to the initial value of metadata.title.
On Devices with API Level <= 29 everything is working as expected.
Media
Not applicable
Bug Report
You will email the zip file produced by adb bugreport to dev.exoplayer@gmail.com after filing this issue.
Hmmm, I'm actually surprised it is working on API levels below 30. We have #33 about this and changing the metadata of the media item is not possible once it is added to the player. Afaik the only way the metadata is updated after adding the media item is if there are some metadata tags in the media itself (like ID3 or Icy).
start playing a MediaItem with alternating MediaMetadata
Can you give me some more details how you update the metdata of the media item? Because once you've added the MediaItem to the player with set/addMediaItem(mediaItem) you can't actually change the metadata of the instance anymore (it is immutable). You would have to replace the intitial media item and that's not possible as per #33.
If you have an URI to the media you are using and can post it here are send it by email (dev.exoplayer@gmail.com), I can test myself.
Yes, so for our use case we need a way to update the current metadata from an external API, and we were aware that the metadata is immutable and can't be changed without a new MediaItem.
So in order to achieve this, we wrapped the Exoplayer and every added Listener with our own implementation of the Player and Player.Listener interface and added our custom implementation of Player.getMediaMetadata(), Listener.onMediaMetadataChanged(), Listener.onMetadata() and some other methods. This custom wrapped player is then used to create the media session.
And so far everything is working fine with our implementation, with the exception of the notification.
We used the DefaultMediaNotificationProvider and even wrote our custom implementation of the MediaNotification.Provider but in both cases the content title of the notification won't change for API Levels > 29, the title is stuck to the initial value of the MediaItem.Metadata.title.
I can't really wrap my head around why the title won't change, even though a new MediaNotification with the correct content title is created and the NotificationManager should replace the existing one, like it's done on devices with API <= 29.
Ah, ok. That makes sense. Quite nifty approach! :) And yeah sounds really odd that it is only partly updated. Thanks for reporting, we need to dig into this and try to repro.
I can repro this behaviour for all API levels above and including 30 and confirm your observation.
For context and as information for us when looking into this, there are two buckets of API levels for which the notification works differently.
API levels below and including 29 that only use assets from the NotificationCompat
For API level below and including 28 there is only the NotificationManagerCompat that has an impact on the media style notification. The media session is not taken into account even when we set the media session token into MediaStyle. This means that the notification displays what we set to the notification as contentTitle and contentText. On these API levels everything works as intended.
API 29 then takes the duration that is sent to the session as part of the MediaMetadataCompat. If METADATA_KEY_DURATION is available, the notification offers a seek bar for seeking within the notification. The text is still taken from the notification just as for API 28 and below. Again, on this API level everything works as intended.
API levels 30 and higher that use MediaMetadataCompat
Starting with API 30, the contentTitle and contentText of the notification is not used anymore. Instead these are taken from the MediaMetadataCompat as documented here.
There are various problems in the Media3 library why this doesn't work.
The EVENT_MEDIA_METADATA_CHANGED is not propagated in MediaSessionLegacyStub, and hence the platform media session is not updated when you trigger this event with an update.
If the update would be propagated, the MediaMetadata (Media3) used to be converted to the MediaMetadataCompat is taken from the MediaItem.metadata, which as we know can't be changed once set. That's kind of consistently incorrect to the EVENT_MEDIA_METADATA_CHANGED not being propagated.
And lastly again consistently, the legacy session is only updated if mediaItem.metadata has changed. Which can never happen for the same media item for the reasons stated in.
After changing 1 - 3 above it works according to my testing.
So given #33 I think we should change this accordingly to make a workaround like yours possible, or we would need to fix #33.
Having same issue here. setContentTitle() doesn't seem to do anything on API 33. As I understand it is used only as a fallback when title couldn't be retrieved from media metadata? Would it be possible to give priority to the title which is set when building MediaNotification, because sometimes there's need to provide custom title in notification for specific mediaItem?
Please read the comments above. From API 33 the System UI build the media notification from the media session. There is no way the library/app can make System UI use the data from the notification.
Activity
marcbaechinger commentedon Dec 9, 2022
Hmmm, I'm actually surprised it is working on API levels below 30. We have #33 about this and changing the metadata of the media item is not possible once it is added to the player. Afaik the only way the metadata is updated after adding the media item is if there are some metadata tags in the media itself (like ID3 or Icy).
Can you give me some more details how you update the metdata of the media item? Because once you've added the
MediaItemto the player withset/addMediaItem(mediaItem)you can't actually change the metadata of the instance anymore (it is immutable). You would have to replace the intitial media item and that's not possible as per #33.If you have an URI to the media you are using and can post it here are send it by email (dev.exoplayer@gmail.com), I can test myself.
6rism0 commentedon Dec 11, 2022
Yes, so for our use case we need a way to update the current metadata from an external API, and we were aware that the metadata is immutable and can't be changed without a new
MediaItem.So in order to achieve this, we wrapped the Exoplayer and every added Listener with our own implementation of the
PlayerandPlayer.Listenerinterface and added our custom implementation ofPlayer.getMediaMetadata(),Listener.onMediaMetadataChanged(),Listener.onMetadata()and some other methods. This custom wrapped player is then used to create the media session.And so far everything is working fine with our implementation, with the exception of the notification.
We used the
DefaultMediaNotificationProviderand even wrote our custom implementation of theMediaNotification.Providerbut in both cases the content title of the notification won't change for API Levels > 29, the title is stuck to the initial value of theMediaItem.Metadata.title.I can't really wrap my head around why the title won't change, even though a new
MediaNotificationwith the correct content title is created and theNotificationManagershould replace the existing one, like it's done on devices with API <= 29.marcbaechinger commentedon Dec 12, 2022
Ah, ok. That makes sense. Quite nifty approach! :) And yeah sounds really odd that it is only partly updated. Thanks for reporting, we need to dig into this and try to repro.
marcbaechinger commentedon Dec 12, 2022
I can repro this behaviour for all API levels above and including 30 and confirm your observation.
For context and as information for us when looking into this, there are two buckets of API levels for which the notification works differently.
API levels below and including 29 that only use assets from the
NotificationCompatFor API level below and including 28 there is only the
NotificationManagerCompatthat has an impact on the media style notification. The media session is not taken into account even when we set the media session token intoMediaStyle. This means that the notification displays what we set to the notification ascontentTitleandcontentText. On these API levels everything works as intended.API 29 then takes the duration that is sent to the session as part of the
MediaMetadataCompat. IfMETADATA_KEY_DURATIONis available, the notification offers a seek bar for seeking within the notification. The text is still taken from the notification just as for API 28 and below. Again, on this API level everything works as intended.For the above API levels, our update of the media metadata triggers an
EVENT_MEDIA_METADATA_CHANGED, that is received by theMediaNotificationManagerand triggers updating the notification. Also,DefaultMediaNotificationProvidercorrectly usescontroller.getMediaMetadata()to build the notification. That corresponds with your observation that it works on these API levels.API levels 30 and higher that use
MediaMetadataCompatStarting with API 30, the
contentTitleandcontentTextof the notification is not used anymore. Instead these are taken from theMediaMetadataCompatas documented here.There are various problems in the Media3 library why this doesn't work.
The
EVENT_MEDIA_METADATA_CHANGEDis not propagated inMediaSessionLegacyStub, and hence the platform media session is not updated when you trigger this event with an update.If the update would be propagated, the
MediaMetadata(Media3) used to be converted to theMediaMetadataCompatis taken from theMediaItem.metadata, which as we know can't be changed once set. That's kind of consistently incorrect to theEVENT_MEDIA_METADATA_CHANGEDnot being propagated.And lastly again consistently, the legacy session is only updated if
mediaItem.metadatahas changed. Which can never happen for the same media item for the reasons stated in.After changing 1 - 3 above it works according to my testing.
So given #33 I think we should change this accordingly to make a workaround like yours possible, or we would need to fix #33.
Thanks for reporting.
Use onMediaMetadataChanged for updating the legacy session
Use onMediaMetadataChanged for updating the legacy session
thawri1 commentedon Apr 30, 2023
so what to do now?!
why setting content title like below not working?
works only on android 10 and below
thawri1 commentedon May 1, 2023
@marcbaechinger
by downgrading media3 from
1.0.1to1.0.0-beta03my code works now!struggling with this for about 3 days!
JaCobbMedia commentedon May 3, 2023
Having same issue here.
setContentTitle()doesn't seem to do anything on API 33. As I understand it is used only as a fallback when title couldn't be retrieved from media metadata? Would it be possible to give priority to the title which is set when buildingMediaNotification, because sometimes there's need to provide custom title in notification for specific mediaItem?marcbaechinger commentedon May 3, 2023
Please read the comments above. From API 33 the System UI build the media notification from the media session. There is no way the library/app can make System UI use the data from the notification.
JaCobbMedia commentedon May 3, 2023
That's a bummer :/ Thanks for the answer anyways
Chore/migrate media 1.0.2 (#10)