use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class ImaServerSideAdInsertionMediaSource method setContentUri.
// Internal methods (called on the playback thread).
private void setContentUri(Uri contentUri) {
if (serverSideAdInsertionMediaSource != null) {
return;
}
MediaItem contentMediaItem = new MediaItem.Builder().setUri(contentUri).setDrmConfiguration(checkNotNull(mediaItem.localConfiguration).drmConfiguration).setLiveConfiguration(mediaItem.liveConfiguration).setCustomCacheKey(mediaItem.localConfiguration.customCacheKey).setStreamKeys(mediaItem.localConfiguration.streamKeys).build();
ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource = new ServerSideAdInsertionMediaSource(contentMediaSourceFactory.createMediaSource(contentMediaItem), componentListener);
this.serverSideAdInsertionMediaSource = serverSideAdInsertionMediaSource;
if (isLiveStream) {
AdPlaybackState liveAdPlaybackState = new AdPlaybackState(adsId).withNewAdGroup(/* adGroupIndex= */
0, /* adGroupTimeUs= */
C.TIME_END_OF_SOURCE).withIsServerSideInserted(/* adGroupIndex= */
0, true);
mainHandler.post(() -> setAdPlaybackState(liveAdPlaybackState));
}
prepareChildSource(/* id= */
null, serverSideAdInsertionMediaSource);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class SessionCallbackBuilderTest method allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable.
@Test
public void allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable() throws Exception {
List<MediaItem> testPlaylist = new ArrayList<>();
testPlaylist.add(TestUtils.createMediaItem(R.raw.video_desks));
UriMediaItem secondPlaylistItem = TestUtils.createMediaItem(R.raw.video_big_buck_bunny);
testPlaylist.add(secondPlaylistItem);
CountDownLatch readAllowedLatch = new CountDownLatch(1);
playerTestRule.setDataSourceInstrumentation(dataSpec -> {
if (dataSpec.uri.equals(secondPlaylistItem.getUri())) {
try {
assertThat(readAllowedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
} catch (Exception e) {
assertWithMessage("Unexpected exception %s", e).fail();
}
}
});
try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).build())) {
assertPlayerResultSuccess(sessionPlayerConnector.setPlaylist(testPlaylist, null));
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
CountDownLatch seekToAllowedForSecondMediaItem = new CountDownLatch(1);
OnAllowedCommandsChangedListener allowedCommandsChangedListener = (controller, allowedCommands) -> {
if (allowedCommands.hasCommand(SessionCommand.COMMAND_CODE_PLAYER_SEEK_TO) && controller.getCurrentMediaItemIndex() == 1) {
seekToAllowedForSecondMediaItem.countDown();
}
};
try (MediaController controller = createConnectedController(session, /* onConnectedListener= */
null, allowedCommandsChangedListener)) {
assertPlayerResultSuccess(sessionPlayerConnector.skipToNextPlaylistItem());
readAllowedLatch.countDown();
assertThat(seekToAllowedForSecondMediaItem.await(CONTROLLER_COMMAND_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
}
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class PlayerWrapper method addPlaylistItem.
public boolean addPlaylistItem(int index, androidx.media2.common.MediaItem media2MediaItem) {
Assertions.checkArgument(!media2Playlist.contains(media2MediaItem));
index = Util.constrainValue(index, 0, media2Playlist.size());
MediaItem exoPlayerMediaItem = Assertions.checkNotNull(mediaItemConverter.convertToExoPlayerMediaItem(media2MediaItem));
player.addMediaItem(index, exoPlayerMediaItem);
return true;
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class PlayerWrapper method setPlaylist.
public boolean setPlaylist(List<androidx.media2.common.MediaItem> playlist, @Nullable MediaMetadata metadata) {
// Check for duplication.
for (int i = 0; i < playlist.size(); i++) {
androidx.media2.common.MediaItem media2MediaItem = playlist.get(i);
Assertions.checkArgument(playlist.indexOf(media2MediaItem) == i);
}
this.playlistMetadata = metadata;
List<MediaItem> exoPlayerMediaItems = new ArrayList<>();
for (int i = 0; i < playlist.size(); i++) {
androidx.media2.common.MediaItem media2MediaItem = playlist.get(i);
MediaItem exoPlayerMediaItem = Assertions.checkNotNull(mediaItemConverter.convertToExoPlayerMediaItem(media2MediaItem));
exoPlayerMediaItems.add(exoPlayerMediaItem);
}
player.setMediaItems(exoPlayerMediaItems, /* resetPosition= */
true);
currentWindowIndex = getCurrentMediaItemIndex();
return true;
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class PlayerWrapper method updatePlaylist.
private void updatePlaylist(Timeline timeline) {
List<androidx.media2.common.MediaItem> media2MediaItemToBeRemoved = new ArrayList<>(media2Playlist);
media2Playlist.clear();
exoPlayerPlaylist.clear();
Timeline.Window window = new Timeline.Window();
int windowCount = timeline.getWindowCount();
for (int i = 0; i < windowCount; i++) {
timeline.getWindow(i, window);
MediaItem exoPlayerMediaItem = window.mediaItem;
androidx.media2.common.MediaItem media2MediaItem = Assertions.checkNotNull(mediaItemConverter.convertToMedia2MediaItem(exoPlayerMediaItem));
exoPlayerPlaylist.add(exoPlayerMediaItem);
media2Playlist.add(media2MediaItem);
media2MediaItemToBeRemoved.remove(media2MediaItem);
}
for (androidx.media2.common.MediaItem item : media2MediaItemToBeRemoved) {
releaseMediaItem(item);
}
}
Aggregations