Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change metadata for a MediaItem during playback #9978

Closed
NikSatyr opened this issue Feb 15, 2022 · 8 comments
Closed

Change metadata for a MediaItem during playback #9978

NikSatyr opened this issue Feb 15, 2022 · 8 comments
Assignees

Comments

@NikSatyr
Copy link

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?

@icbaker
Copy link
Collaborator

icbaker commented 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
Copy link
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 :))

@NikSatyr
Copy link
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

@NikSatyr
Copy link
Author

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

@NikSatyr
Copy link
Author

any updates here?

@icbaker
Copy link
Collaborator

icbaker commented 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 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.

@icbaker icbaker changed the title How to supply custom metadata? Change metadata for a MediaItem during playback Mar 7, 2022
rohitjoins pushed a commit to androidx/media that referenced this issue Jul 14, 2023
This changes all MediaSources in our library to allow updates to
their MediaItems (if supported).

Issue: google/ExoPlayer#9978
Issue: #33
PiperOrigin-RevId: 546808812
rohitjoins pushed a commit that referenced this issue Jul 14, 2023
This changes all MediaSources in our library to allow updates to
their MediaItems (if supported).

Issue: #9978
Issue: androidx/media#33
PiperOrigin-RevId: 546808812
@npasyuk
Copy link

npasyuk commented Oct 8, 2023

Hi, when is an update planned with these changes?

@icbaker
Copy link
Collaborator

icbaker commented Mar 25, 2024

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

@icbaker icbaker closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants