mirror of
https://github.com/samsonjs/media.git
synced 2026-04-11 12:15:47 +00:00
Add android unit test for setting playback speed of a legacy session
PiperOrigin-RevId: 546282819
This commit is contained in:
parent
0b7d9a945c
commit
a884186e58
1 changed files with 61 additions and 0 deletions
|
|
@ -139,6 +139,67 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||
assertThat(controller.isConnected()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPlaybackSpeed() throws Exception {
|
||||
PlaybackStateCompat playbackStateCompat =
|
||||
new PlaybackStateCompat.Builder()
|
||||
.setState(
|
||||
PlaybackStateCompat.STATE_PAUSED,
|
||||
/* position= */ 10_000L,
|
||||
/* playbackSpeed= */ 1.0f)
|
||||
.setActions(PlaybackStateCompat.ACTION_SET_PLAYBACK_SPEED)
|
||||
.build();
|
||||
session.setPlaybackState(playbackStateCompat);
|
||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
AtomicReference<PlaybackParameters> parametersRef = new AtomicReference<>();
|
||||
controller.addListener(
|
||||
new Player.Listener() {
|
||||
@Override
|
||||
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
|
||||
parametersRef.set(playbackParameters);
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
threadTestRule
|
||||
.getHandler()
|
||||
.postAndSync(
|
||||
() -> {
|
||||
assertThat(
|
||||
controller
|
||||
.getAvailableCommands()
|
||||
.contains(Player.COMMAND_SET_SPEED_AND_PITCH))
|
||||
.isTrue();
|
||||
controller.setPlaybackSpeed(2.0f);
|
||||
});
|
||||
|
||||
assertThat(countDownLatch.await(1000, MILLISECONDS)).isTrue();
|
||||
assertThat(parametersRef.get().speed).isEqualTo(2.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPlaybackSpeed_actionSetPlaybackSpeedNotAvailable_commandNotAvailable()
|
||||
throws Exception {
|
||||
PlaybackStateCompat playbackStateCompat =
|
||||
new PlaybackStateCompat.Builder()
|
||||
.setState(PlaybackStateCompat.STATE_PAUSED, 10_000L, /* playbackSpeed= */ 1.0f)
|
||||
.setActions(PlaybackStateCompat.ACTION_PAUSE)
|
||||
.build();
|
||||
session.setPlaybackState(playbackStateCompat);
|
||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||
|
||||
threadTestRule
|
||||
.getHandler()
|
||||
.postAndSync(
|
||||
() ->
|
||||
assertThat(
|
||||
controller
|
||||
.getAvailableCommands()
|
||||
.contains(Player.COMMAND_SET_SPEED_AND_PITCH))
|
||||
.isFalse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disconnected_bySessionRelease() throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue