Search in sources :

Example 6 with MediaItem

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

the class SessionPlayerConnectorTest method removePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce.

@Test
@LargeTest
public void removePlaylistItem_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 removeIndex = 3;
    playlist.remove(removeIndex);
    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.removePlaylistItem(removeIndex);
    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 7 with MediaItem

use of androidx.media2.common.MediaItem 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 8 with MediaItem

use of androidx.media2.common.MediaItem 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 9 with MediaItem

use of androidx.media2.common.MediaItem 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 10 with MediaItem

use of androidx.media2.common.MediaItem 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)

Aggregations

MediaItem (androidx.media2.common.MediaItem)22 UriMediaItem (androidx.media2.common.UriMediaItem)18 LargeTest (androidx.test.filters.LargeTest)16 Test (org.junit.Test)16 SessionPlayer (androidx.media2.common.SessionPlayer)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 MediumTest (androidx.test.filters.MediumTest)13 SmallTest (androidx.test.filters.SmallTest)13 ArrayList (java.util.ArrayList)13 MediaMetadata (androidx.media2.common.MediaMetadata)11 CallbackMediaItem (androidx.media2.common.CallbackMediaItem)9 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 Nullable (androidx.annotation.Nullable)7 FileMediaItem (androidx.media2.common.FileMediaItem)5 Uri (android.net.Uri)4 SessionCommand (androidx.media2.session.SessionCommand)4 SessionCommandGroup (androidx.media2.session.SessionCommandGroup)4 List (java.util.List)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3