use of androidx.media3.common.MediaMetadata in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setPlaylist_byUnderlyingPlayerAfterPrepare_notifiesOnPlaylistChanged.
@Test
@LargeTest
public void setPlaylist_byUnderlyingPlayerAfterPrepare_notifiesOnPlaylistChanged() throws Exception {
List<MediaItem> playlistToSessionPlayer = TestUtils.createPlaylist(2);
List<MediaItem> playlistToExoPlayer = TestUtils.createPlaylist(4);
DefaultMediaItemConverter converter = new DefaultMediaItemConverter();
List<com.google.android.exoplayer2.MediaItem> exoMediaItems = new ArrayList<>();
for (MediaItem mediaItem : playlistToExoPlayer) {
exoMediaItems.add(converter.convertToExoPlayerMediaItem(mediaItem));
}
CountDownLatch onPlaylistChangedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlaylistChanged(SessionPlayer player, @Nullable List<MediaItem> list, @Nullable MediaMetadata metadata) {
if (Util.areEqual(list, playlistToExoPlayer)) {
onPlaylistChangedLatch.countDown();
}
}
});
sessionPlayerConnector.prepare();
sessionPlayerConnector.setPlaylist(playlistToSessionPlayer, /* metadata= */
null);
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> playerTestRule.getExoPlayer().setMediaItems(exoMediaItems));
assertThat(onPlaylistChangedLatch.await(PLAYLIST_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
use of androidx.media3.common.MediaMetadata 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.media3.common.MediaMetadata 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.media3.common.MediaMetadata 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.media3.common.MediaMetadata 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