Search in sources :

Example 16 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method removeNonCurrentMediaItem_doesNotNotifyPositionDiscontinuity.

@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void removeNonCurrentMediaItem_doesNotNotifyPositionDiscontinuity() {
    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);
    verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 17 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method setMediaItems_replaceExistingPlaylist_notifiesPositionDiscontinuity.

// Verifies deprecated callback being called correctly.
@SuppressWarnings("deprecation")
@Test
public void setMediaItems_replaceExistingPlaylist_notifiesPositionDiscontinuity() {
    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, /* streamTypes= */
    new int[] { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
    new long[] { 20_000, 20_000 }, /* positionMs= */
    2000L);
    // Replacing existing playlist.
    castPlayer.setMediaItems(secondPlaylist, /* startWindowIndex= */
    0, /* startPositionMs= */
    1000L);
    updateTimeLine(secondPlaylist, /* mediaQueueItemIds= */
    new int[] { 3 }, /* currentItemId= */
    3, /* streamTypes= */
    new int[] { MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
    new long[] { 20_000 }, /* positionMs= */
    1000L);
    Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
    2, /* windowIndex= */
    1, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(), /* periodUid= */
    2, /* periodIndex= */
    1, /* positionMs= */
    2000, /* contentPositionMs= */
    2000, /* adGroupIndex= */
    C.INDEX_UNSET, /* adIndexInAdGroup= */
    C.INDEX_UNSET);
    Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
    3, /* windowIndex= */
    0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(3).build(), /* periodUid= */
    3, /* periodIndex= */
    0, /* positionMs= */
    1000, /* contentPositionMs= */
    1000, /* adGroupIndex= */
    C.INDEX_UNSET, /* adIndexInAdGroup= */
    C.INDEX_UNSET);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener).onPositionDiscontinuity(eq(DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Also used : Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

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(androidx.media3.common.MediaItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method removeCurrentMediaItem_byRemoteClient_notifiesMediaItemTransition.

@Test
public void removeCurrentMediaItem_byRemoteClient_notifiesMediaItemTransition() {
    MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
    1);
    MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
    2);
    List<MediaItem> mediaItems = ImmutableList.of(mediaItem1, mediaItem2);
    castPlayer.addMediaItems(mediaItems);
    updateTimeLine(mediaItems, new int[] { 1, 2 }, /* currentItemId= */
    1);
    // Update with the new timeline after removal on the device.
    updateTimeLine(ImmutableList.of(mediaItem2), /* mediaQueueItemIds= */
    new int[] { 2 }, /* currentItemId= */
    2);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener, times(2)).onMediaItemTransition(mediaItemCaptor.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
    List<MediaItem> capturedMediaItems = mediaItemCaptor.getAllValues();
    assertThat(capturedMediaItems.get(0).localConfiguration.tag).isEqualTo(mediaItem1.localConfiguration.tag);
    assertThat(capturedMediaItems.get(1).localConfiguration.tag).isEqualTo(mediaItem2.localConfiguration.tag);
}
Also used : InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 20 with MediaItem

use of androidx.media3.common.MediaItem in project media by androidx.

the class CastPlayerTest method addMediaItems_fillsTimeline.

@SuppressWarnings("ConstantConditions")
@Test
public void addMediaItems_fillsTimeline() {
    Timeline.Window window = new Timeline.Window();
    int[] mediaQueueItemIds = createMediaQueueItemIds(/* numberOfIds= */
    5);
    List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
    addMediaItemsAndUpdateTimeline(mediaItems, mediaQueueItemIds);
    Timeline currentTimeline = castPlayer.getCurrentTimeline();
    for (int i = 0; i < mediaItems.size(); i++) {
        assertThat(currentTimeline.getWindow(/* windowIndex= */
        i, window).uid).isEqualTo(mediaItems.get(i).localConfiguration.tag);
    }
}
Also used : Timeline(androidx.media3.common.Timeline) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (androidx.media3.common.MediaItem)281 Test (org.junit.Test)255 LargeTest (androidx.test.filters.LargeTest)76 CountDownLatch (java.util.concurrent.CountDownLatch)72 Timeline (androidx.media3.common.Timeline)68 Player (androidx.media3.common.Player)57 Nullable (androidx.annotation.Nullable)53 ArrayList (java.util.ArrayList)52 AtomicReference (java.util.concurrent.atomic.AtomicReference)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)45 Bundle (android.os.Bundle)36 MediumTest (androidx.test.filters.MediumTest)31 MediaSource (androidx.media3.exoplayer.source.MediaSource)27 MediaMetadata (androidx.media3.common.MediaMetadata)26 PositionInfo (androidx.media3.common.Player.PositionInfo)25 QueueItem (android.support.v4.media.session.MediaSessionCompat.QueueItem)23 MediaItem (androidx.media2.common.MediaItem)23 SmallTest (androidx.test.filters.SmallTest)23 InOrder (org.mockito.InOrder)20 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)19