use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastTimeline method getWindow.
@Override
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
long durationUs = durationsUs[windowIndex];
boolean isDynamic = durationUs == C.TIME_UNSET;
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(ids[windowIndex]).build();
return window.set(/* uid= */
ids[windowIndex], /* mediaItem= */
mediaItem, /* manifest= */
null, /* presentationStartTimeMs= */
C.TIME_UNSET, /* windowStartTimeMs= */
C.TIME_UNSET, /* elapsedRealtimeEpochOffsetMs= */
C.TIME_UNSET, /* isSeekable= */
!isDynamic, isDynamic, isLive[windowIndex] ? mediaItem.liveConfiguration : null, defaultPositionsUs[windowIndex], durationUs, /* firstPeriodIndex= */
windowIndex, /* lastPeriodIndex= */
windowIndex, /* positionInFirstPeriodUs= */
0);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method addMediaItems_insertAtIndex_callsRemoteMediaClient.
@SuppressWarnings("ConstantConditions")
@Test
public void addMediaItems_insertAtIndex_callsRemoteMediaClient() {
int[] mediaQueueItemIds = createMediaQueueItemIds(/* numberOfIds= */
2);
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
addMediaItemsAndUpdateTimeline(mediaItems, mediaQueueItemIds);
String uri = "http://www.google.com/video3";
MediaItem anotherMediaItem = new MediaItem.Builder().setUri(uri).setMimeType(MimeTypes.APPLICATION_MPD).build();
// Add another on position 1
int index = 1;
castPlayer.addMediaItems(index, Collections.singletonList(anotherMediaItem));
verify(mockRemoteMediaClient).queueInsertItems(queueItemsArgumentCaptor.capture(), eq((int) mediaItems.get(index).localConfiguration.tag), any());
MediaQueueItem[] mediaQueueItems = queueItemsArgumentCaptor.getValue();
assertThat(mediaQueueItems[0].getMedia().getContentId()).isEqualTo(uri);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method seekTo_sameWindow_doesNotNotifyMediaItemTransition.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekTo_sameWindow_doesNotNotifyMediaItemTransition() {
when(mockRemoteMediaClient.seek(anyLong())).thenReturn(mockPendingResult);
int[] mediaQueueItemIds = new int[] { 1, 2 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
castPlayer.seekTo(/* windowIndex= */
0, /* positionMs= */
1234);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onMediaItemTransition(any(), eq(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 CastPlayerTest method isCommandAvailable_duringLiveItem_isTrueForSeekToNext.
@Test
public void isCommandAvailable_duringLiveItem_isTrueForSeekToNext() {
MediaItem mediaItem = createMediaItem(/* mediaQueueItemId= */
1);
List<MediaItem> mediaItems = ImmutableList.of(mediaItem);
int[] mediaQueueItemIds = new int[] { 1 };
int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_LIVE };
long[] durationsMs = new long[] { C.TIME_UNSET };
castPlayer.addMediaItem(mediaItem);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1, streamTypes, durationsMs, /* positionMs= */
C.TIME_UNSET);
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class CastPlayerTest method seekForward_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekForward_notifiesPositionDiscontinuity() {
when(mockRemoteMediaClient.seek(anyLong())).thenReturn(mockPendingResult);
int[] mediaQueueItemIds = new int[] { 1 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
int currentItemId = 1;
int[] streamTypes = new int[] { MediaInfo.STREAM_TYPE_BUFFERED };
long[] durationsMs = new long[] { 2 * C.DEFAULT_SEEK_FORWARD_INCREMENT_MS };
long positionMs = 0;
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
castPlayer.seekForward();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
0, /* contentPositionMs= */
0, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, mediaItem, /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
C.DEFAULT_SEEK_FORWARD_INCREMENT_MS, /* contentPositionMs= */
C.DEFAULT_SEEK_FORWARD_INCREMENT_MS, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_SEEK));
inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Aggregations