Search in sources :

Example 26 with SessionPlayer

use of androidx.media2.common.SessionPlayer in project ExoPlayer by google.

the class SessionPlayerConnectorTest method setMediaItem_withVideoResource_notifiesOnPlaybackCompleted.

@Test
@LargeTest
public void setMediaItem_withVideoResource_notifiesOnPlaybackCompleted() throws Exception {
    TestUtils.loadResource(R.raw.video_desks, 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 27 with SessionPlayer

use of androidx.media2.common.SessionPlayer in project ExoPlayer by google.

the class SessionPlayerConnectorTest method addPlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce.

@Test
@LargeTest
public void addPlaylistItem_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 addIndex = 2;
    MediaItem newMediaItem = TestUtils.createMediaItem();
    playlist.add(addIndex, 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.addPlaylistItem(addIndex, 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) 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 28 with SessionPlayer

use of androidx.media2.common.SessionPlayer in project ExoPlayer by google.

the class SessionPlayerConnectorTest method play_withPlaylist_notifiesOnCurrentMediaItemChangedAndOnPlaybackCompleted.

@Test
@LargeTest
public void play_withPlaylist_notifiesOnCurrentMediaItemChangedAndOnPlaybackCompleted() 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));
    CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        int currentMediaItemChangedCount = 0;

        @Override
        public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item) {
            assertThat(item).isEqualTo(player.getCurrentMediaItem());
            int expectedCurrentIndex = currentMediaItemChangedCount++;
            assertThat(player.getCurrentMediaItemIndex()).isEqualTo(expectedCurrentIndex);
            assertThat(item).isEqualTo(playlist.get(expectedCurrentIndex));
        }

        @Override
        public void onPlaybackCompleted(SessionPlayer player) {
            onPlaybackCompletedLatch.countDown();
        }
    });
    assertThat(sessionPlayerConnector.setPlaylist(playlist, null)).isNotNull();
    assertThat(sessionPlayerConnector.prepare()).isNotNull();
    assertThat(sessionPlayerConnector.play()).isNotNull();
    assertThat(onPlaybackCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
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)

Aggregations

LargeTest (androidx.test.filters.LargeTest)26 Test (org.junit.Test)26 SessionPlayer (androidx.media2.common.SessionPlayer)25 MediumTest (androidx.test.filters.MediumTest)25 SmallTest (androidx.test.filters.SmallTest)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 MediaItem (androidx.media2.common.MediaItem)16 UriMediaItem (androidx.media2.common.UriMediaItem)15 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)11 ArrayList (java.util.ArrayList)9 MediaMetadata (androidx.media2.common.MediaMetadata)8 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)5 Nullable (androidx.annotation.Nullable)3 AudioAttributesCompat (androidx.media.AudioAttributesCompat)2 SessionCommand (androidx.media2.session.SessionCommand)2 SessionCommandGroup (androidx.media2.session.SessionCommandGroup)2 List (java.util.List)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Context (android.content.Context)1 Uri (android.net.Uri)1