media icon indicating copy to clipboard operation
media copied to clipboard

How to update the metadata for a currentMediaItem with CastPlayer

Open FilipKastrupGP opened this issue 1 year ago • 4 comments

I am working with an audio streaming app. I have a ReplaceableForwardingPlayer like in the UAMP project. The forwardingplayer switches between an ExoPlayer and a CastPlayer.

I need to control and change the metadata for a mediaItem. With the Exoplayer I can just replaceMediaItem(...) and it updates the metadata seamlessly: With the CastPlayer this is not the case. It reloads the entire mediaItem.

Is there a way to update the metadata on a CastPlayer?

FilipKastrupGP avatar Jun 28 '24 09:06 FilipKastrupGP

This is not seamlessly supported on CastPlayer at the moment. I can mark it as a feature request but we won't get around to work on it soon.

If you want to add support, I think you can amend CastPlayer.replaceMediaItems to check if just the metadata changed, and if so, call a new method on CastTimelineTracker that updates the internal item data only (without touching the remote cast client at all). The remote cast player metadata won't be updated though in this scenario (that is the title etc you'd see on the cast device). There is a method like queueUpdateItems, but it's documented that it's not possible to update just the metadata once the item has been loaded.

tonihei avatar Jun 28 '24 14:06 tonihei

Thanks for the quick reply.

For anyone else how has this problem,- I made it work by making a copy of the CastPlayer class and changing the empty method

@Override
public void onMetadataUpdated() {}

to

@Override
public void onMetadataUpdated() {
        if (remoteMediaClient != null) {
            currentTimeline = timelineTracker.getCastTimeline(remoteMediaClient);
        }
    }

This depend on the cast-recevier doing the metadata changes to the MediaQueueItem.

FilipKastrupGP avatar Jun 29 '24 11:06 FilipKastrupGP

making a copy of the CastPlayer class

If you already figured out how to improve this, do you want to upload a PR instead to merge it into our codebase? If not, we can make the same change ourselves too.

tonihei avatar Jul 01 '24 07:07 tonihei

Sure. I'll make a pr.

FilipKastrupGP avatar Jul 02 '24 07:07 FilipKastrupGP