Search in sources :

Example 1 with LargeTest

use of androidx.test.filters.LargeTest in project ExoPlayer by google.

the class SessionPlayerConnectorTest method setMediaItem_withAudioResource_notifiesOnPlaybackCompleted.

@Test
@LargeTest
public void setMediaItem_withAudioResource_notifiesOnPlaybackCompleted() throws Exception {
    TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
    CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onPlaybackCompleted(SessionPlayer player) {
            onPlaybackCompletedLatch.countDown();
        }
    });
    sessionPlayerConnector.prepare();
    sessionPlayerConnector.play();
    // waiting to complete
    assertThat(onPlaybackCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
    assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
}
Also used : SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) 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 LargeTest

use of androidx.test.filters.LargeTest in project ExoPlayer by google.

the class SessionPlayerConnectorTest method prepare_notifiesBufferingCompletedOnce.

@Test
@LargeTest
public void prepare_notifiesBufferingCompletedOnce() throws Throwable {
    TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
    CountDownLatch onBufferingCompletedLatch = new CountDownLatch(2);
    CopyOnWriteArrayList<Integer> bufferingStateChanges = new CopyOnWriteArrayList<>();
    SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {

        @Override
        public void onBufferingStateChanged(SessionPlayer player, @Nullable MediaItem item, int buffState) {
            bufferingStateChanges.add(buffState);
            if (buffState == SessionPlayer.BUFFERING_STATE_COMPLETE) {
                onBufferingCompletedLatch.countDown();
            }
        }
    };
    sessionPlayerConnector.registerPlayerCallback(executor, callback);
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    assertWithMessage("Expected BUFFERING_STATE_COMPLETE only once. Full changes are %s", bufferingStateChanges).that(onBufferingCompletedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
    assertThat(bufferingStateChanges).isNotEmpty();
    int lastIndex = bufferingStateChanges.size() - 1;
    assertWithMessage("Didn't end with BUFFERING_STATE_COMPLETE. Full changes are %s", bufferingStateChanges).that(bufferingStateChanges.get(lastIndex)).isEqualTo(SessionPlayer.BUFFERING_STATE_COMPLETE);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(androidx.annotation.Nullable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) 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 3 with LargeTest

use of androidx.test.filters.LargeTest in project ExoPlayer by google.

the class SessionPlayerConnectorTest method seekTo_skipsUnnecessarySeek.

@Test
@LargeTest
public void seekTo_skipsUnnecessarySeek() throws Exception {
    CountDownLatch readAllowedLatch = new CountDownLatch(1);
    playerTestRule.setDataSourceInstrumentation(dataSpec -> {
        try {
            assertThat(readAllowedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
        } catch (Exception e) {
            assertWithMessage("Unexpected exception %s", e).fail();
        }
    });
    sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem(R.raw.video_big_buck_bunny));
    // prepare() will be pending until readAllowed is countDowned.
    sessionPlayerConnector.prepare();
    CopyOnWriteArrayList<Long> positionChanges = new CopyOnWriteArrayList<>();
    long testIntermediateSeekToPosition1 = 3000;
    long testIntermediateSeekToPosition2 = 2000;
    long testFinalSeekToPosition = 1000;
    CountDownLatch onSeekCompletedLatch = new CountDownLatch(1);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onSeekCompleted(SessionPlayer player, long position) {
            // Do not assert here, because onSeekCompleted() can be called after the player is
            // closed.
            positionChanges.add(position);
            if (position == testFinalSeekToPosition) {
                onSeekCompletedLatch.countDown();
            }
        }
    });
    ListenableFuture<PlayerResult> seekFuture1 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition1);
    ListenableFuture<PlayerResult> seekFuture2 = sessionPlayerConnector.seekTo(testIntermediateSeekToPosition2);
    ListenableFuture<PlayerResult> seekFuture3 = sessionPlayerConnector.seekTo(testFinalSeekToPosition);
    readAllowedLatch.countDown();
    assertThat(seekFuture1.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
    assertThat(seekFuture2.get().getResultCode()).isEqualTo(RESULT_INFO_SKIPPED);
    assertThat(seekFuture3.get().getResultCode()).isEqualTo(RESULT_SUCCESS);
    assertThat(onSeekCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
    assertThat(positionChanges).containsNoneOf(testIntermediateSeekToPosition1, testIntermediateSeekToPosition2);
    assertThat(positionChanges).contains(testFinalSeekToPosition);
}
Also used : TestUtils.assertPlayerResult(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult) PlayerResult(androidx.media2.common.SessionPlayer.PlayerResult) SessionPlayer(androidx.media2.common.SessionPlayer) AtomicLong(java.util.concurrent.atomic.AtomicLong) CountDownLatch(java.util.concurrent.CountDownLatch) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) 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 4 with LargeTest

use of androidx.test.filters.LargeTest in project ExoPlayer by google.

the class SessionPlayerConnectorTest method seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException.

@Test
@LargeTest
public void seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException() throws Exception {
    TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    ExoPlayer exoPlayer = playerTestRule.getExoPlayer();
    List<ListenableFuture<PlayerResult>> futures = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        futures.add(sessionPlayerConnector.seekTo(4123));
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> exoPlayer.seekTo(1243));
    }
    for (ListenableFuture<PlayerResult> future : futures) {
        assertThat(future.get().getResultCode()).isAnyOf(PlayerResult.RESULT_INFO_SKIPPED, PlayerResult.RESULT_SUCCESS);
    }
}
Also used : TestUtils.assertPlayerResult(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult) PlayerResult(androidx.media2.common.SessionPlayer.PlayerResult) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) 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 5 with LargeTest

use of androidx.test.filters.LargeTest in project ExoPlayer by google.

the class SessionPlayerConnectorTest method setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged.

@Test
@LargeTest
public void setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged() throws Throwable {
    TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    CountDownLatch onPlaybackSpeedChangedLatch = new CountDownLatch(1);
    SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {

        @Override
        public void onPlaybackSpeedChanged(SessionPlayer player, float speed) {
            assertThat(speed).isWithin(FLOAT_TOLERANCE).of(0.5f);
            onPlaybackSpeedChangedLatch.countDown();
        }
    };
    sessionPlayerConnector.registerPlayerCallback(executor, callback);
    sessionPlayerConnector.setPlaybackSpeed(0.5f);
    assertThat(onPlaybackSpeedChangedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
Also used : SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

LargeTest (androidx.test.filters.LargeTest)36 Test (org.junit.Test)36 MediumTest (androidx.test.filters.MediumTest)29 SmallTest (androidx.test.filters.SmallTest)29 SessionPlayer (androidx.media2.common.SessionPlayer)24 CountDownLatch (java.util.concurrent.CountDownLatch)23 MediaItem (androidx.media2.common.MediaItem)13 UriMediaItem (androidx.media2.common.UriMediaItem)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 ArrayList (java.util.ArrayList)9 MediaMetadata (androidx.media2.common.MediaMetadata)7 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)7 AudioAttributesCompat (androidx.media.AudioAttributesCompat)3 PlayerResult (androidx.media2.common.SessionPlayer.PlayerResult)3 ViewInteraction (androidx.test.espresso.ViewInteraction)3 TestUtils.assertPlayerResult (com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CancellationSignal (android.os.CancellationSignal)2