Fix PlayerWrapper's creation of VolumeProviderCompat

When hardware buttons are used to control the volume of the remote device, the call propagates to `MediaSessionCompat.setPlaybackToRemote(volumeProviderCompat)`. However, `volumeProviderCompat` was created incorrectly when the new device volume commands were present (COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS and COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS), i.e. with volumeControlType = `VOLUME_CONTROL_FIXED`. This resulted in `VolumeProviderCompat` which doesn't call `onSetVolumeTo` or `onAdjustVolume` and hence doesn't propagate the calls to the `Player`. Instead, it only worked with the deprecated commands which ensured the volumeControlType was `VOLUME_CONTROL_ABSOLUTE`.

This bug was introduced in c71e4bf1ff (1.0 media 3 release) when `PlayerWrapper`'s call to `createVolumeProviderCompat` was mostly rewritten to handle the new commands, but the two if-statements were not amended. Note: this change fixes the bug only for Android 11 and below. For 12 and above, there is a tracking bug for the regression that was introduced: https://issuetracker.google.com/issues/201546605

http://Issue: androidx/media#554

#minor-release

PiperOrigin-RevId: 554966361
This commit is contained in:
jbibik 2023-08-08 22:51:53 +00:00 committed by Tianyi Feng
parent e8a18e208a
commit dedccc596e
2 changed files with 10 additions and 2 deletions

View File

@ -125,6 +125,12 @@
`Result` that didn't support this which produced an
`UnsuportedOperationException`
([#78](https://github.com/androidx/media/issues/78)).
* Fix the way `PlayerWrapper` creates a `VolumeProviderCompat` by
determining `volumeControlType` through both legacy commands
(`COMMAND_ADJUST_DEVICE_VOLUME` and `COMMAND_SET_DEVICE_VOLUME`) and new
commands (`COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS` and
`COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS`)
([#554](https://github.com/androidx/media/issues/554)).
* UI:
* Add a `Player.Listener` implementation for Wear OS devices that handles
playback suppression due to

View File

@ -1031,9 +1031,11 @@ import java.util.List;
}
Commands availableCommands = getAvailableCommands();
int volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_FIXED;
if (availableCommands.contains(COMMAND_ADJUST_DEVICE_VOLUME)) {
if (availableCommands.containsAny(
COMMAND_ADJUST_DEVICE_VOLUME, COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS)) {
volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_RELATIVE;
if (availableCommands.contains(COMMAND_SET_DEVICE_VOLUME)) {
if (availableCommands.containsAny(
COMMAND_SET_DEVICE_VOLUME, COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS)) {
volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE;
}
}