Search in sources :

Example 16 with MediaItem

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);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem)

Example 17 with MediaItem

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);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem) Test(org.junit.Test)

Example 18 with MediaItem

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());
}
Also used : InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 19 with MediaItem

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();
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 20 with MediaItem

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());
}
Also used : Player(com.google.android.exoplayer2.Player) InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)160 Test (org.junit.Test)151 MediaSource (com.google.android.exoplayer2.source.MediaSource)31 ArrayList (java.util.ArrayList)29 Timeline (com.google.android.exoplayer2.Timeline)25 InOrder (org.mockito.InOrder)20 Nullable (androidx.annotation.Nullable)19 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)19 Player (com.google.android.exoplayer2.Player)17 Uri (android.net.Uri)15 Listener (com.google.android.exoplayer2.Player.Listener)15 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)15 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)15 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)12