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 (cherry picked from commit 79fab6783e07ea594410be347c8a3d6e1124707d)
This commit is contained in:
parent
58cf3a7ba2
commit
0f6a1eb6b8
@ -8,6 +8,10 @@
|
||||
* Fix issue where last frame may not be rendered if the last sample with
|
||||
frames is dequeued without reading the 'end of stream' sample.
|
||||
([#11079](https://github.com/google/ExoPlayer/issues/11079)).
|
||||
* Session:
|
||||
* Fix issue where `MediaController` doesn't update its available commands
|
||||
when connected to a legacy `MediaSessionCompat` that updates its
|
||||
actions.
|
||||
|
||||
### 1.0.1 (2023-04-18)
|
||||
|
||||
|
@ -1885,13 +1885,11 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
? newLegacyPlayerInfo.playbackInfoCompat.getVolumeControl()
|
||||
: VolumeProviderCompat.VOLUME_CONTROL_FIXED;
|
||||
availablePlayerCommands =
|
||||
(oldControllerInfo.availablePlayerCommands == Commands.EMPTY)
|
||||
? MediaUtils.convertToPlayerCommands(
|
||||
newLegacyPlayerInfo.playbackStateCompat,
|
||||
volumeControlType,
|
||||
sessionFlags,
|
||||
isSessionReady)
|
||||
: oldControllerInfo.availablePlayerCommands;
|
||||
MediaUtils.convertToPlayerCommands(
|
||||
newLegacyPlayerInfo.playbackStateCompat,
|
||||
volumeControlType,
|
||||
sessionFlags,
|
||||
isSessionReady);
|
||||
|
||||
PlaybackException playerError =
|
||||
MediaUtils.convertToPlaybackException(newLegacyPlayerInfo.playbackStateCompat);
|
||||
|
@ -1502,6 +1502,36 @@ public class MediaControllerWithMediaSessionCompatTest {
|
||||
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
|
||||
public void setPlaybackToRemote_notifiesDeviceInfoAndVolume() throws Exception {
|
||||
int volumeControlType = VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user