use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method removeMediaItem_atTheEnd_notifiesAvailableCommandsChanged.
@Test
public void removeMediaItem_atTheEnd_notifiesAvailableCommandsChanged() {
Player.Commands defaultCommands = createWithDefaultCommands();
Player.Commands commandsWithSeekToNextWindow = createWithDefaultCommands(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT);
Player.Commands emptyTimelineCommands = createWithDefaultCommands(/* isTimelineEmpty= */
true);
MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
1);
MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
2);
MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
3);
castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3));
updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
new int[] { 1, 2, 3 }, /* currentItemId= */
1);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow);
// Check that there were no other calls to onAvailableCommandsChanged.
verify(mockListener).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
2);
updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2), /* mediaQueueItemIds= */
new int[] { 1, 2 }, /* currentItemId= */
1);
verify(mockListener).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
1);
updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
new int[] { 1 }, /* currentItemId= */
1);
verify(mockListener).onAvailableCommandsChanged(defaultCommands);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
0);
updateTimeLine(ImmutableList.of(), /* mediaQueueItemIds= */
new int[0], /* currentItemId= */
C.INDEX_UNSET);
verify(mockListener).onAvailableCommandsChanged(emptyTimelineCommands);
verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method autoTransition_notifiesMediaItemTransition.
@Test
public void autoTransition_notifiesMediaItemTransition() {
int[] mediaQueueItemIds = new int[] { 1, 2 };
// When the remote Cast player transitions to an item that wasn't played before, the media state
// delivers the duration for that media item which updates the timeline accordingly.
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
2);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onMediaItemTransition(any(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
inOrder.verify(mockListener).onMediaItemTransition(mediaItemCaptor.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_AUTO));
inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
assertThat(mediaItemCaptor.getValue().localConfiguration.tag).isEqualTo(2);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method clearMediaItems_notifiesMediaItemTransition.
@Test
public void clearMediaItems_notifiesMediaItemTransition() {
int[] mediaQueueItemIds = new int[] { 1, 2 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
castPlayer.clearMediaItems();
updateTimeLine(/* mediaItems= */
ImmutableList.of(), /* mediaQueueItemIds= */
new int[0], /* currentItemId= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onMediaItemTransition(any(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
inOrder.verify(mockListener).onMediaItemTransition(/* mediaItem= */
null, Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED);
inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayer method getCurrentPositionInfo.
private PositionInfo getCurrentPositionInfo() {
Timeline currentTimeline = getCurrentTimeline();
@Nullable Object newPeriodUid = null;
@Nullable Object newWindowUid = null;
@Nullable MediaItem newMediaItem = null;
if (!currentTimeline.isEmpty()) {
newPeriodUid = currentTimeline.getPeriod(getCurrentPeriodIndex(), period, /* setIds= */
true).uid;
newWindowUid = currentTimeline.getWindow(period.windowIndex, window).uid;
newMediaItem = window.mediaItem;
}
return new PositionInfo(newWindowUid, getCurrentMediaItemIndex(), newMediaItem, newPeriodUid, getCurrentPeriodIndex(), getCurrentPosition(), getContentPosition(), /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayer method seekTo.
// We still call Listener#onSeekProcessed() for backwards compatibility with listeners that
// don't implement onPositionDiscontinuity().
@SuppressWarnings("deprecation")
@Override
public void seekTo(int mediaItemIndex, long positionMs) {
MediaStatus mediaStatus = getMediaStatus();
// We assume the default position is 0. There is no support for seeking to the default position
// in RemoteMediaClient.
positionMs = positionMs != C.TIME_UNSET ? positionMs : 0;
if (mediaStatus != null) {
if (getCurrentMediaItemIndex() != mediaItemIndex) {
remoteMediaClient.queueJumpToItem((int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null).setResultCallback(seekResultCallback);
} else {
remoteMediaClient.seek(positionMs).setResultCallback(seekResultCallback);
}
PositionInfo oldPosition = getCurrentPositionInfo();
pendingSeekCount++;
pendingSeekWindowIndex = mediaItemIndex;
pendingSeekPositionMs = positionMs;
PositionInfo newPosition = getCurrentPositionInfo();
listeners.queueEvent(Player.EVENT_POSITION_DISCONTINUITY, listener -> {
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_SEEK);
listener.onPositionDiscontinuity(oldPosition, newPosition, DISCONTINUITY_REASON_SEEK);
});
if (oldPosition.mediaItemIndex != newPosition.mediaItemIndex) {
// TODO(internal b/182261884): queue `onMediaItemTransition` event when the media item is
// repeated.
MediaItem mediaItem = getCurrentTimeline().getWindow(mediaItemIndex, window).mediaItem;
listeners.queueEvent(Player.EVENT_MEDIA_ITEM_TRANSITION, listener -> listener.onMediaItemTransition(mediaItem, MEDIA_ITEM_TRANSITION_REASON_SEEK));
}
updateAvailableCommandsAndNotifyIfChanged();
} else if (pendingSeekCount == 0) {
listeners.queueEvent(/* eventFlag= */
C.INDEX_UNSET, Listener::onSeekProcessed);
}
listeners.flushEvents();
}
Aggregations