Search in sources :

Example 11 with LargeTest

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

the class SessionPlayerConnectorTest method replacePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce.

@Ignore("Internal ref: b/168860979")
@Test
@LargeTest
public void replacePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce() throws Exception {
    List<MediaItem> playlist = TestUtils.createPlaylist(10);
    assertPlayerResultSuccess(sessionPlayerConnector.setPlaylist(playlist, /* metadata= */
    null));
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    CountDownLatch onPlaylistChangedLatch = new CountDownLatch(2);
    int replaceIndex = 2;
    MediaItem newMediaItem = TestUtils.createMediaItem(R.raw.video_big_buck_bunny);
    playlist.set(replaceIndex, newMediaItem);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onPlaylistChanged(SessionPlayer player, @Nullable List<MediaItem> list, @Nullable MediaMetadata metadata) {
            assertThat(list).isEqualTo(playlist);
            onPlaylistChangedLatch.countDown();
        }
    });
    sessionPlayerConnector.replacePlaylistItem(replaceIndex, newMediaItem);
    assertThat(onPlaylistChangedLatch.await(PLAYLIST_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
    assertThat(onPlaylistChangedLatch.getCount()).isEqualTo(1);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) 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 12 with LargeTest

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

the class SessionPlayerConnectorTest method setPlaylist_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce.

@Test
@LargeTest
public void setPlaylist_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce() throws Exception {
    List<MediaItem> playlist = TestUtils.createPlaylist(10);
    CountDownLatch onPlaylistChangedLatch = new CountDownLatch(2);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onPlaylistChanged(SessionPlayer player, @Nullable List<MediaItem> list, @Nullable MediaMetadata metadata) {
            assertThat(list).isEqualTo(playlist);
            onPlaylistChangedLatch.countDown();
        }
    });
    sessionPlayerConnector.setPlaylist(playlist, /* metadata= */
    null);
    sessionPlayerConnector.prepare();
    assertThat(onPlaylistChangedLatch.await(PLAYLIST_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
    assertThat(onPlaylistChangedLatch.getCount()).isEqualTo(1);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) 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 13 with LargeTest

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

the class SessionPlayerConnectorTest method skipToNextAndPrevious_calledInARow_notifiesOnCurrentMediaItemChanged.

@Test
@LargeTest
public void skipToNextAndPrevious_calledInARow_notifiesOnCurrentMediaItemChanged() throws Exception {
    List<MediaItem> playlist = new ArrayList<>();
    playlist.add(TestUtils.createMediaItem(R.raw.video_1));
    playlist.add(TestUtils.createMediaItem(R.raw.video_2));
    playlist.add(TestUtils.createMediaItem(R.raw.video_3));
    assertThat(sessionPlayerConnector.setPlaylist(playlist, /* metadata= */
    null)).isNotNull();
    // STEP 1: prepare()
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    // STEP 2: skipToNextPlaylistItem()
    CountDownLatch onNextMediaItemLatch = new CountDownLatch(1);
    SessionPlayer.PlayerCallback skipToNextTestCallback = new SessionPlayer.PlayerCallback() {

        @Override
        public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item) {
            super.onCurrentMediaItemChanged(player, item);
            assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1);
            assertThat(item).isEqualTo(player.getCurrentMediaItem());
            assertThat(item).isEqualTo(playlist.get(1));
            onNextMediaItemLatch.countDown();
        }
    };
    sessionPlayerConnector.registerPlayerCallback(executor, skipToNextTestCallback);
    assertPlayerResultSuccess(sessionPlayerConnector.skipToNextPlaylistItem());
    assertThat(onNextMediaItemLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
    sessionPlayerConnector.unregisterPlayerCallback(skipToNextTestCallback);
    // STEP 3: skipToPreviousPlaylistItem()
    CountDownLatch onPreviousMediaItemLatch = new CountDownLatch(1);
    SessionPlayer.PlayerCallback skipToPreviousTestCallback = new SessionPlayer.PlayerCallback() {

        @Override
        public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item) {
            super.onCurrentMediaItemChanged(player, item);
            assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0);
            assertThat(item).isEqualTo(player.getCurrentMediaItem());
            assertThat(item).isEqualTo(playlist.get(0));
            onPreviousMediaItemLatch.countDown();
        }
    };
    sessionPlayerConnector.registerPlayerCallback(executor, skipToPreviousTestCallback);
    assertPlayerResultSuccess(sessionPlayerConnector.skipToPreviousPlaylistItem());
    assertThat(onPreviousMediaItemLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
    sessionPlayerConnector.unregisterPlayerCallback(skipToPreviousTestCallback);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) 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 14 with LargeTest

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

the class SessionPlayerConnectorTest method movePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce.

@Test
@LargeTest
public void movePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce() throws Exception {
    List<MediaItem> playlist = new ArrayList<>();
    playlist.add(TestUtils.createMediaItem(R.raw.video_1));
    playlist.add(TestUtils.createMediaItem(R.raw.video_2));
    playlist.add(TestUtils.createMediaItem(R.raw.video_3));
    assertPlayerResultSuccess(sessionPlayerConnector.setPlaylist(playlist, /* metadata= */
    null));
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    CountDownLatch onPlaylistChangedLatch = new CountDownLatch(2);
    int moveFromIndex = 0;
    int moveToIndex = 2;
    playlist.add(moveToIndex, playlist.remove(moveFromIndex));
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onPlaylistChanged(SessionPlayer player, @Nullable List<MediaItem> list, @Nullable MediaMetadata metadata) {
            assertThat(list).isEqualTo(playlist);
            onPlaylistChangedLatch.countDown();
        }
    });
    sessionPlayerConnector.movePlaylistItem(moveFromIndex, moveToIndex);
    assertThat(onPlaylistChangedLatch.await(PLAYLIST_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isFalse();
    assertThat(onPlaylistChangedLatch.getCount()).isEqualTo(1);
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MediaMetadata(androidx.media2.common.MediaMetadata) 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 15 with LargeTest

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

the class SessionPlayerConnectorTest method getPlayerState_withPrepareAndPlayAndPause_changesAsExpected.

@Test
@LargeTest
public void getPlayerState_withPrepareAndPlayAndPause_changesAsExpected() throws Exception {
    TestUtils.loadResource(R.raw.audio, sessionPlayerConnector);
    AudioAttributesCompat attributes = new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
    sessionPlayerConnector.setAudioAttributes(attributes);
    sessionPlayerConnector.setRepeatMode(SessionPlayer.REPEAT_MODE_ALL);
    assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_IDLE);
    assertPlayerResultSuccess(sessionPlayerConnector.prepare());
    assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
    assertPlayerResultSuccess(sessionPlayerConnector.play());
    assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(PLAYER_STATE_PLAYING);
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) 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