Search in sources :

Example 6 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class CastPlayerTest method removeNonCurrentMediaItem_doesNotNotifyMediaItemTransition.

@Test
public void removeNonCurrentMediaItem_doesNotNotifyMediaItemTransition() {
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
    int[] mediaQueueItemIds = new int[] { 1, 2 };
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1);
    castPlayer.removeMediaItem(/* index= */
    1);
    updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
    new int[] { 1 }, /* currentItemId= */
    1);
    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 7 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class CastPlayerTest method setMediaItems_replaceExistingPlaylist_notifiesMediaItemTransition.

@Test
public void setMediaItems_replaceExistingPlaylist_notifiesMediaItemTransition() {
    List<MediaItem> firstPlaylist = new ArrayList<>();
    String uri1 = "http://www.google.com/video1";
    String uri2 = "http://www.google.com/video2";
    firstPlaylist.add(new MediaItem.Builder().setUri(uri1).setMimeType(MimeTypes.APPLICATION_MPD).build());
    firstPlaylist.add(new MediaItem.Builder().setUri(uri2).setMimeType(MimeTypes.APPLICATION_MP4).build());
    ImmutableList<MediaItem> secondPlaylist = ImmutableList.of(new MediaItem.Builder().setUri(Uri.EMPTY).setMimeType(MimeTypes.APPLICATION_MPD).build());
    castPlayer.setMediaItems(firstPlaylist, /* startWindowIndex= */
    1, /* startPositionMs= */
    2000L);
    updateTimeLine(firstPlaylist, /* mediaQueueItemIds= */
    new int[] { 1, 2 }, /* currentItemId= */
    2);
    // Replacing existing playlist.
    castPlayer.setMediaItems(secondPlaylist, /* startWindowIndex= */
    0, /* startPositionMs= */
    1000L);
    updateTimeLine(secondPlaylist, /* mediaQueueItemIds= */
    new int[] { 3 }, /* currentItemId= */
    3);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener, times(2)).onMediaItemTransition(mediaItemCaptor.capture(), eq(MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
    assertThat(mediaItemCaptor.getAllValues().get(1).localConfiguration.tag).isEqualTo(3);
}
Also used : InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class CastPlayerTest method updateTimeLine.

private void updateTimeLine(List<MediaItem> mediaItems, int[] mediaQueueItemIds, int currentItemId, int[] streamTypes, long[] durationsMs, long positionMs) {
    // Set up mocks to allow the player to update the timeline.
    List<MediaQueueItem> queueItems = new ArrayList<>();
    for (int i = 0; i < mediaQueueItemIds.length; i++) {
        MediaItem mediaItem = mediaItems.get(i);
        int mediaQueueItemId = mediaQueueItemIds[i];
        int streamType = streamTypes[i];
        long durationMs = durationsMs[i];
        MediaInfo.Builder mediaInfoBuilder = new MediaInfo.Builder(mediaItem.localConfiguration.uri.toString()).setStreamType(streamType).setContentType(mediaItem.localConfiguration.mimeType);
        if (durationMs != C.TIME_UNSET) {
            mediaInfoBuilder.setStreamDuration(durationMs);
        }
        MediaInfo mediaInfo = mediaInfoBuilder.build();
        MediaQueueItem mediaQueueItem = mock(MediaQueueItem.class);
        when(mediaQueueItem.getItemId()).thenReturn(mediaQueueItemId);
        when(mediaQueueItem.getMedia()).thenReturn(mediaInfo);
        queueItems.add(mediaQueueItem);
        if (mediaQueueItemId == currentItemId) {
            when(mockRemoteMediaClient.getCurrentItem()).thenReturn(mediaQueueItem);
            when(mockMediaStatus.getMediaInfo()).thenReturn(mediaInfo);
        }
    }
    if (positionMs != C.TIME_UNSET) {
        when(mockRemoteMediaClient.getApproximateStreamPosition()).thenReturn(positionMs);
    }
    when(mockMediaQueue.getItemIds()).thenReturn(mediaQueueItemIds);
    when(mockMediaStatus.getQueueItems()).thenReturn(queueItems);
    when(mockMediaStatus.getCurrentItemId()).thenReturn(currentItemId == C.INDEX_UNSET ? 0 : currentItemId);
    // Call listener to update the timeline of the player.
    remoteMediaClientCallback.onStatusUpdated();
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 9 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class CastPlayerTest method seekTo_otherWindow_notifiesMediaItemTransition.

@Test
public void seekTo_otherWindow_notifiesMediaItemTransition() {
    when(mockRemoteMediaClient.queueJumpToItem(anyInt(), anyLong(), eq(null))).thenReturn(mockPendingResult);
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
    int[] mediaQueueItemIds = new int[] { 1, 2 };
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
    1);
    castPlayer.seekTo(/* windowIndex= */
    1, /* positionMs= */
    1234);
    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_SEEK));
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
    assertThat(mediaItemCaptor.getValue().localConfiguration.tag).isEqualTo(mediaItem2.localConfiguration.tag);
}
Also used : InOrder(org.mockito.InOrder) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 10 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class CastPlayerTest method seekBack_notifiesPositionDiscontinuity.

@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void seekBack_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[] { 3 * C.DEFAULT_SEEK_BACK_INCREMENT_MS };
    long positionMs = 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS;
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
    castPlayer.seekBack();
    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= */
    2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* contentPositionMs= */
    2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS, /* 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_BACK_INCREMENT_MS, /* contentPositionMs= */
    C.DEFAULT_SEEK_BACK_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