Skip to content

Change metadata for a MediaItem during playback #9978

Closed

Description

@NikSatyr

I'm having a hard time figuring out how to supply custom metadata for the ExoPlayer (or maybe it's better to say side-load). We support some sort of radio functionality, which is delivered via ProgressiveMediaSource. The problem is that the radio stream may contain malformed metadata due to the human factor (e.g. incorrect title, missing artwork). However, we have a dedicated "now playing" endpoint on our server that returns 100% accurate metadata (don't ask me why :)).

What I need to achieve is to periodically update the metadata (by calling the above mentioned endpoint) (for instance to update the track info in the notification) without re-setting the media item with the radio url. This is because the radio stream url is always the same and we set it only once, while songs on the radio are obviously being changed, and we'd like to reflect the song changes (title, artist, artwork etc) in the notification.

Previously we've been using mediaSession.setMetadata() for this purpose, but as we migrated to media2 this method is marked as library restricted, so I don't think it's a good option.

Could you please advise the solution?

Activity

  1. self-assigned this
    on Feb 15, 2022
  2. icbaker commented on Feb 15, 2022

    @icbaker
    Collaborator

    I believe Player#setPlaylistMetadata(MediaMetadata) should work for this use-case. Can you give that a try?

    If that doesn't work, please provide a minimal reproducible example that demonstrates the problem in a way that we can build locally.

    This could be an Android Studio project on GitHub, or zipped up and sent to dev.exoplayer@gmail.com using a subject in the format "Issue #1234", where "#1234" should be replaced with your issue number. Please also update this issue to indicate you’ve done this.

  3. NikSatyr commented on Feb 15, 2022

    @NikSatyr
    Author

    yep, I've already tried Player.setPlaylistMetadata() and it did not work. As far as I can see in the ExoPlayer source code, it does not actually affect anything important.

    you can find a reproducible example here: https://github.com/NikSatyr/media2-radio. please see RadioMetadataUpdater class as it's responsible for fetching the radio metadata. I've grabbed the BBC radio stream URL as it does not provide correct metadata for the player notification manager, so it pretty much resembles our production situation. Let's assume that metadata returned by getCustomMetadata() is fully correct (in the real app we'd make an API call there) and should be displayed in the notification. So far I have not managed to achieve it.

    PS: Make sure you follow the instructions from the README to setup the ExoPlayer locally (I understand that ExoPlayer devs perfectly know how to do this, but still don't forget to do so :))

  4. NikSatyr commented on Feb 16, 2022

    @NikSatyr
    Author

    I'd also like to point out that we need this metadata not only for the notification (so some tweaks to MediaDescriptionAdapter would not be enough), but for AnalyticsListener & some other parts. Thus we need to feed this correct metadata directly into the player / MediaSession

  5. NikSatyr commented on Feb 18, 2022

    @NikSatyr
    Author

    @icbaker sorry to bother you, but this blocks our development process. did you have a chance to take a look?

  6. NikSatyr commented on Feb 25, 2022

    @NikSatyr
    Author

    any updates here?

  7. icbaker commented on Mar 7, 2022

    @icbaker
    Collaborator

    Sorry for the delay looking into this. Thanks for the repro project, it was really helpful and nice and simple.

    This is a limitation of ExoPlayer: It's not currently possible to change the item metadata of a currently-playing MediaItem - because if you try and change the whole MediaItem it will result in the whole MediaSource being re-created, and playback will not be continuous. It's the same issue tracked by androidx/media#33.

    I'm going to mark this as an enhancement.

  8. changed the title [-]How to supply custom metadata?[/-] [+]Change metadata for a MediaItem during playback[/+] on Mar 7, 2022
  9. npasyuk commented on Oct 8, 2023

    @npasyuk

    Hi, when is an update planned with these changes?

  10. icbaker commented on Mar 25, 2024

    @icbaker
    Collaborator

    This is now possible using Player.replaceMediaItem(s).

  11. locked and limited conversation to collaborators on May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions