Update available commands when MediaSessionCompat actions change
This is a bug currently, where commands are created once but never updated again if the actions in MediaSessionCompat are changed. PiperOrigin-RevId: 525999084
This commit is contained in:
parent
2de89ca2ce
commit
79fab6783e
@ -43,6 +43,9 @@
|
|||||||
* `void increaseDeviceVolume(int)`
|
* `void increaseDeviceVolume(int)`
|
||||||
* `void decreaseDeviceVolume(int)`
|
* `void decreaseDeviceVolume(int)`
|
||||||
* `void setDeviceMuted(boolean, int)`
|
* `void setDeviceMuted(boolean, int)`
|
||||||
|
* Fix issue where `MediaController` doesn't update its available commands
|
||||||
|
when connected to a legacy `MediaSessionCompat` that updates its
|
||||||
|
actions.
|
||||||
* Audio:
|
* Audio:
|
||||||
* Fix bug where some playbacks fail when tunneling is enabled and
|
* Fix bug where some playbacks fail when tunneling is enabled and
|
||||||
`AudioProcessors` are active, e.g. for gapless trimming
|
`AudioProcessors` are active, e.g. for gapless trimming
|
||||||
|
@ -1920,13 +1920,11 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
|||||||
? newLegacyPlayerInfo.playbackInfoCompat.getVolumeControl()
|
? newLegacyPlayerInfo.playbackInfoCompat.getVolumeControl()
|
||||||
: VolumeProviderCompat.VOLUME_CONTROL_FIXED;
|
: VolumeProviderCompat.VOLUME_CONTROL_FIXED;
|
||||||
availablePlayerCommands =
|
availablePlayerCommands =
|
||||||
(oldControllerInfo.availablePlayerCommands == Commands.EMPTY)
|
MediaUtils.convertToPlayerCommands(
|
||||||
? MediaUtils.convertToPlayerCommands(
|
newLegacyPlayerInfo.playbackStateCompat,
|
||||||
newLegacyPlayerInfo.playbackStateCompat,
|
volumeControlType,
|
||||||
volumeControlType,
|
sessionFlags,
|
||||||
sessionFlags,
|
isSessionReady);
|
||||||
isSessionReady)
|
|
||||||
: oldControllerInfo.availablePlayerCommands;
|
|
||||||
|
|
||||||
PlaybackException playerError =
|
PlaybackException playerError =
|
||||||
MediaUtils.convertToPlaybackException(newLegacyPlayerInfo.playbackStateCompat);
|
MediaUtils.convertToPlaybackException(newLegacyPlayerInfo.playbackStateCompat);
|
||||||
|
@ -1513,6 +1513,36 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
assertThat(errorFromGetterRef.get().getMessage()).isEqualTo(testConvertedErrorMessage);
|
assertThat(errorFromGetterRef.get().getMessage()).isEqualTo(testConvertedErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setPlaybackState_withActions_updatesAndNotifiesAvailableCommands() throws Exception {
|
||||||
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
AtomicReference<Player.Commands> commandsFromParamRef = new AtomicReference<>();
|
||||||
|
AtomicReference<Player.Commands> commandsFromGetterRef = new AtomicReference<>();
|
||||||
|
Player.Listener listener =
|
||||||
|
new Player.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onAvailableCommandsChanged(Player.Commands commands) {
|
||||||
|
commandsFromParamRef.set(commands);
|
||||||
|
commandsFromGetterRef.set(controller.getAvailableCommands());
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
controller.addListener(listener);
|
||||||
|
|
||||||
|
session.setPlaybackState(
|
||||||
|
new PlaybackStateCompat.Builder()
|
||||||
|
.setActions(
|
||||||
|
PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_FAST_FORWARD)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
|
assertThat(commandsFromParamRef.get().contains(Player.COMMAND_PLAY_PAUSE)).isTrue();
|
||||||
|
assertThat(commandsFromParamRef.get().contains(Player.COMMAND_SEEK_FORWARD)).isTrue();
|
||||||
|
assertThat(commandsFromGetterRef.get().contains(Player.COMMAND_PLAY_PAUSE)).isTrue();
|
||||||
|
assertThat(commandsFromGetterRef.get().contains(Player.COMMAND_SEEK_FORWARD)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setPlaybackToRemote_notifiesDeviceInfoAndVolume() throws Exception {
|
public void setPlaybackToRemote_notifiesDeviceInfoAndVolume() throws Exception {
|
||||||
int volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE;
|
int volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user