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());
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations