Search in sources :

Example 1 with COMMAND_SET_REPEAT_MODE

use of androidx.media3.common.Player.COMMAND_SET_REPEAT_MODE in project media by androidx.

the class ExoPlayerTest method isCommandAvailable_isTrueForAvailableCommands.

@Test
public void isCommandAvailable_isTrueForAvailableCommands() {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
    assertThat(player.isCommandAvailable(COMMAND_PLAY_PAUSE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_PREPARE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_STOP)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_DEFAULT_POSITION)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SET_SPEED_AND_PITCH)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_SHUFFLE_MODE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_REPEAT_MODE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TIMELINE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_MEDIA_ITEMS_METADATA)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_MEDIA_ITEMS_METADATA)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_AUDIO_ATTRIBUTES)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_ADJUST_DEVICE_VOLUME)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TEXT)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_SET_TRACK_SELECTION_PARAMETERS)).isTrue();
    assertThat(player.isCommandAvailable(COMMAND_GET_TRACK_INFOS)).isTrue();
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 2 with COMMAND_SET_REPEAT_MODE

use of androidx.media3.common.Player.COMMAND_SET_REPEAT_MODE in project media by androidx.

the class MediaControllerListenerTest method onAvailableCommandsChanged_isCalledByPlayerChange.

/**
 * This also tests {@link MediaController#getAvailableCommands()}.
 */
@Test
public void onAvailableCommandsChanged_isCalledByPlayerChange() throws Exception {
    Commands commandsWithAllCommands = new Player.Commands.Builder().addAllCommands().build();
    remoteSession.getMockPlayer().notifyAvailableCommandsChanged(commandsWithAllCommands);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken(), /* connectionHints= */
    null, /* listener= */
    null);
    AtomicReference<Commands> availableCommandsFromParamRef = new AtomicReference<>();
    AtomicReference<Commands> availableCommandsFromGetterRef = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onAvailableCommandsChanged(Commands availableCommands) {
            availableCommandsFromParamRef.set(availableCommands);
            availableCommandsFromGetterRef.set(controller.getAvailableCommands());
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    Commands commandsWithSetRepeat = createPlayerCommandsWith(COMMAND_SET_REPEAT_MODE);
    remoteSession.getMockPlayer().notifyAvailableCommandsChanged(commandsWithSetRepeat);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(availableCommandsFromParamRef.get()).isEqualTo(commandsWithSetRepeat);
    assertThat(availableCommandsFromGetterRef.get()).isEqualTo(commandsWithSetRepeat);
}
Also used : RemoteMockPlayer(androidx.media3.session.RemoteMediaSession.RemoteMockPlayer) Player(androidx.media3.common.Player) Commands(androidx.media3.common.Player.Commands) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 3 with COMMAND_SET_REPEAT_MODE

use of androidx.media3.common.Player.COMMAND_SET_REPEAT_MODE in project media by androidx.

the class MediaControllerListenerTest method onAvailableCommandsChanged_isCalledBySessionChange.

/**
 * This also tests {@link MediaController#getAvailableCommands()}.
 */
@Test
public void onAvailableCommandsChanged_isCalledBySessionChange() throws Exception {
    Commands commandsWithAllCommands = new Player.Commands.Builder().addAllCommands().build();
    remoteSession.getMockPlayer().notifyAvailableCommandsChanged(commandsWithAllCommands);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken(), /* connectionHints= */
    null, /* listener= */
    null);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Commands> availableCommandsFromParamRef = new AtomicReference<>();
    AtomicReference<Commands> availableCommandsFromGetterRef = new AtomicReference<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onAvailableCommandsChanged(Commands availableCommands) {
            availableCommandsFromParamRef.set(availableCommands);
            availableCommandsFromGetterRef.set(controller.getAvailableCommands());
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    Commands commandsWithSetRepeat = createPlayerCommandsWith(COMMAND_SET_REPEAT_MODE);
    remoteSession.setAvailableCommands(SessionCommands.EMPTY, commandsWithSetRepeat);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(availableCommandsFromParamRef.get()).isEqualTo(commandsWithSetRepeat);
    assertThat(availableCommandsFromGetterRef.get()).isEqualTo(commandsWithSetRepeat);
}
Also used : RemoteMockPlayer(androidx.media3.session.RemoteMediaSession.RemoteMockPlayer) Player(androidx.media3.common.Player) Commands(androidx.media3.common.Player.Commands) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Player (androidx.media3.common.Player)2 Commands (androidx.media3.common.Player.Commands)2 RemoteMockPlayer (androidx.media3.session.RemoteMediaSession.RemoteMockPlayer)2 LargeTest (androidx.test.filters.LargeTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)1 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)1