Change metadata for a MediaItem during playback #9978
Description
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
icbaker commentedon Feb 15, 2022
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.
NikSatyr commentedon Feb 15, 2022
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
RadioMetadataUpdaterclass 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 bygetCustomMetadata()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 :))
NikSatyr commentedon Feb 16, 2022
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 /MediaSessionNikSatyr commentedon Feb 18, 2022
@icbaker sorry to bother you, but this blocks our development process. did you have a chance to take a look?
NikSatyr commentedon Feb 25, 2022
any updates here?
icbaker commentedon Mar 7, 2022
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 wholeMediaItemit will result in the wholeMediaSourcebeing 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.
[-]How to supply custom metadata?[/-][+]Change metadata for a MediaItem during playback[/+]Make MediaItems updateable
Make MediaItems updateable
npasyuk commentedon Oct 8, 2023
Hi, when is an update planned with these changes?
icbaker commentedon Mar 25, 2024
This is now possible using
Player.replaceMediaItem(s).