google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Improve documentation on routing of volume key events to active MediaSession #5050

Open deRonbrown opened 5 years ago

deRonbrown commented 5 years ago

Issue description

When playing content using the CastPlayer, the device's physical volume buttons should control the receiver device's volume. This behaves as expected when the CastPlayer is contained within an Activity. However, when the CastPlayer is contained within a Service (such as a MediaBrowserServiceCompat) the physical volume buttons change the sender device's media volume.

Reproduction steps

I've created 2 sample projects:

Link to test content

Test mp4 file is used in sample projects above.

Version of ExoPlayer being used

Core 2.8.4 and Cast Extension 2.8.4

Device(s) and version(s) of Android being used

Reproduces on 9.0 and 8.1.0.

deRonbrown commented 5 years ago

I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.

After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.

This doesn't seem intuitive, so can you add this info to your Cast extension docs for future developers who may come across this issue?

AquilesCanta commented 5 years ago

I'll have a look. Thanks for doing the research!