Search in sources :

Example 1 with COMMAND_PLAY_PAUSE

use of com.google.android.exoplayer2.Player.COMMAND_PLAY_PAUSE in project ExoPlayer by google.

the class SessionPlayerConnectorTest method play_withForwardingPlayer_isSkipped.

@Test
@LargeTest
public void play_withForwardingPlayer_isSkipped() throws Exception {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    Player forwardingPlayer = null;
    SessionPlayerConnector playerConnector = null;
    try {
        Player exoPlayer = new ExoPlayer.Builder(context).setLooper(Looper.myLooper()).build();
        forwardingPlayer = new ForwardingPlayer(exoPlayer) {

            @Override
            public boolean isCommandAvailable(int command) {
                if (command == COMMAND_PLAY_PAUSE) {
                    return false;
                }
                return super.isCommandAvailable(command);
            }

            @Override
            public Commands getAvailableCommands() {
                return super.getAvailableCommands().buildUpon().remove(COMMAND_PLAY_PAUSE).build();
            }
        };
        playerConnector = new SessionPlayerConnector(forwardingPlayer);
        assertPlayerResult(playerConnector.play(), RESULT_INFO_SKIPPED);
    } finally {
        if (playerConnector != null) {
            playerConnector.close();
        }
        if (forwardingPlayer != null) {
            forwardingPlayer.release();
        }
    }
}
Also used : Player(com.google.android.exoplayer2.Player) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) SessionPlayer(androidx.media2.common.SessionPlayer) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 2 with COMMAND_PLAY_PAUSE

use of com.google.android.exoplayer2.Player.COMMAND_PLAY_PAUSE in project ExoPlayer by google.

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(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SessionPlayer (androidx.media2.common.SessionPlayer)1 LargeTest (androidx.test.filters.LargeTest)1 MediumTest (androidx.test.filters.MediumTest)1 SmallTest (androidx.test.filters.SmallTest)1 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 ForwardingPlayer (com.google.android.exoplayer2.ForwardingPlayer)1 Player (com.google.android.exoplayer2.Player)1 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)1 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)1