Skip to content

Commit

Permalink
Fix PlayerWrapper's creation of VolumeProviderCompat
Browse files Browse the repository at this point in the history
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 c71e4bf (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: #554

#minor-release

PiperOrigin-RevId: 554966361
  • Loading branch information
oceanjules authored and tianyif committed Aug 10, 2023
1 parent e8a18e2 commit dedccc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,11 @@ public VolumeProviderCompat createVolumeProviderCompat() {
}
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;
}
}
Expand Down

0 comments on commit dedccc5

Please sign in to comment.