use of androidx.media2.common.SessionPlayer 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.SessionPlayer 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.SessionPlayer 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.SessionPlayer 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);
}
use of androidx.media2.common.SessionPlayer in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setRepeatMode_withRepeatAll_continuesToPlayPlaylistWithoutBeingCompleted.
@Test
@LargeTest
public void setRepeatMode_withRepeatAll_continuesToPlayPlaylistWithoutBeingCompleted() 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));
int listSize = playlist.size();
// Any value more than list size + 1, to see repeat mode with the recorded video.
CopyOnWriteArrayList<MediaItem> currentMediaItemChanges = new CopyOnWriteArrayList<>();
PlayerCallbackForPlaylist callback = new PlayerCallbackForPlaylist(playlist, listSize + 2) {
@Override
public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item) {
super.onCurrentMediaItemChanged(player, item);
currentMediaItemChanges.add(item);
countDown();
}
@Override
public void onPlaybackCompleted(SessionPlayer player) {
assertWithMessage("Playback shouldn't be completed, Actual changes were %s", currentMediaItemChanges).fail();
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
assertThat(sessionPlayerConnector.setPlaylist(playlist, null)).isNotNull();
assertThat(sessionPlayerConnector.prepare()).isNotNull();
assertThat(sessionPlayerConnector.setRepeatMode(SessionPlayer.REPEAT_MODE_ALL)).isNotNull();
assertThat(sessionPlayerConnector.play()).isNotNull();
assertWithMessage("Current media item didn't change as expected. Actual changes were %s", currentMediaItemChanges).that(callback.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
int expectedMediaItemIndex = 0;
for (MediaItem mediaItemInPlaybackOrder : currentMediaItemChanges) {
assertWithMessage("Unexpected media item for %sth playback. Actual changes were %s", expectedMediaItemIndex, currentMediaItemChanges).that(mediaItemInPlaybackOrder).isEqualTo(playlist.get(expectedMediaItemIndex));
expectedMediaItemIndex = (expectedMediaItemIndex + 1) % listSize;
}
}
Aggregations