androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
Apache License 2.0
1.34k stars 315 forks source link

What is the recommended way to listen for CastPlayer playback state changes? #1475

Closed y20k closed 1 week ago

y20k commented 1 week ago

I am developing a radio app using media3. The app has a MediaLibraryService for playback and a Fragment that controls the UI. The Fragment listens to playback changes using a Player.Listener that has been added to a MediaController. That all works great so far.

I recently began integrating Google Cast into the app. Playback through a CastPlayer in the MediaLibraryService works fine. But now I am stuck: How do I receive information about CastPlayer playback state changes in my Fragment? The existing Player.Listener (basically created in the way recommended here) does not get called at the moment.

y20k commented 1 week ago

I just found the media3 branch of UAMP. My issue was a buggy function that handled swapping between CastPlayer and ExoPlayer. As soon as I adapted ReplaceableForwardingPlayer for my needs, my problem was more or less solved.