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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations