Skip to content

Media Notification does not update content title on API Level > 29 #219

Closed

Description

@6rism0

Media3 Version

1.0.0-beta03

Devices that reproduce the issue

Emulator API Level > 29

Devices that do not reproduce the issue

Emulator API Level <= 29

Reproducible in the demo app?

Not tested

Reproduction steps

  1. start playing a MediaItem with alternating MediaMetadata
  2. 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

Activity

  1. marcbaechinger commented on Dec 9, 2022

    @marcbaechinger
    Contributor

    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.

  2. 6rism0 commented on Dec 11, 2022

    @6rism0
    Author

    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.

  3. marcbaechinger commented on Dec 12, 2022

    @marcbaechinger
    Contributor

    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.

  4. marcbaechinger commented on Dec 12, 2022

    @marcbaechinger
    Contributor

    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.

    For the above API levels, our update of the media metadata triggers an EVENT_MEDIA_METADATA_CHANGED, that is received by the MediaNotificationManager and triggers updating the notification. Also, DefaultMediaNotificationProvider correctly uses controller.getMediaMetadata() to build the notification. That corresponds with your observation that it works on these API levels.

    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.

    1. 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.

    2. 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.

    3. 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.

    Thanks for reporting.

  5. thawri1 commented on Apr 30, 2023

    @thawri1

    so what to do now?!

    why setting content title like below not working?

    val notificationBuilder = NotificationCompat.Builder(
                context,
                AppConstants.PLAYER_NOTIFICATION_CHANNEL_ID
            )
                .setSmallIcon(R.drawable.notification)
                .setContentTitle("test title")
                .setContentText("test text")
                .setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_large_icon))
                .setStyle(MediaStyleNotificationHelper.MediaStyle(session))
    

    works only on android 10 and below

  6. thawri1 commented on May 1, 2023

    @thawri1

    so what to do now?!

    why setting content title like below not working?

    val notificationBuilder = NotificationCompat.Builder( context, AppConstants.PLAYER_NOTIFICATION_CHANNEL_ID ) .setSmallIcon(R.drawable.notification) .setContentTitle("test title") .setContentText("test text") .setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_large_icon)) .setStyle(MediaStyleNotificationHelper.MediaStyle(session))

    works only on android 10 and below

    @marcbaechinger
    by downgrading media3 from 1.0.1 to 1.0.0-beta03 my code works now!
    struggling with this for about 3 days!

  7. JaCobbMedia commented on May 3, 2023

    @JaCobbMedia

    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?

  8. marcbaechinger commented on May 3, 2023

    @marcbaechinger
    Contributor

    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.

  9. JaCobbMedia commented on May 3, 2023

    @JaCobbMedia

    That's a bummer :/ Thanks for the answer anyways

  10. added a commit that references this issue on Jun 22, 2023
  11. locked and limited conversation to collaborators on Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions