use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method removeCurrentMediaItem_notifiesMediaItemTransition.
@Test
public void removeCurrentMediaItem_notifiesMediaItemTransition() {
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= */
0);
// Update with the new timeline after removal.
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());
assertThat(mediaItemCaptor.getAllValues().get(0).localConfiguration.tag).isEqualTo(mediaItem1.localConfiguration.tag);
assertThat(mediaItemCaptor.getAllValues().get(1).localConfiguration.tag).isEqualTo(mediaItem2.localConfiguration.tag);
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method removeMediaItem_atTheStart_notifiesAvailableCommandsChanged.
@Test
public void removeMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
when(mockRemoteMediaClient.queueJumpToItem(anyInt(), anyLong(), eq(null))).thenReturn(mockPendingResult);
Player.Commands defaultCommands = createWithDefaultCommands();
Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
Player.Commands emptyTimelineCommands = createWithDefaultCommands(/* isTimelineEmpty= */
true);
MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
1);
MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
2);
MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
3);
castPlayer.addMediaItems(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3));
updateTimeLine(ImmutableList.of(mediaItem1, mediaItem2, mediaItem3), /* mediaQueueItemIds= */
new int[] { 1, 2, 3 }, /* currentItemId= */
3);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
// Check that there were no other calls to onAvailableCommandsChanged.
verify(mockListener).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
0);
updateTimeLine(ImmutableList.of(mediaItem2, mediaItem3), /* mediaQueueItemIds= */
new int[] { 2, 3 }, /* currentItemId= */
3);
verify(mockListener).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
0);
updateTimeLine(ImmutableList.of(mediaItem3), /* mediaQueueItemIds= */
new int[] { 3 }, /* currentItemId= */
3);
verify(mockListener).onAvailableCommandsChanged(defaultCommands);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
castPlayer.removeMediaItem(/* index= */
0);
updateTimeLine(ImmutableList.of(), /* mediaQueueItemIds= */
new int[0], /* currentItemId= */
C.INDEX_UNSET);
verify(mockListener).onAvailableCommandsChanged(emptyTimelineCommands);
verify(mockListener, times(3)).onAvailableCommandsChanged(any());
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method addMediaItem_atTheStart_notifiesAvailableCommandsChanged.
@Test
public void addMediaItem_atTheStart_notifiesAvailableCommandsChanged() {
Player.Commands defaultCommands = createWithDefaultCommands();
Player.Commands commandsWithSeekToPreviousWindow = createWithDefaultCommands(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM);
MediaItem mediaItem1 = createMediaItem(/* mediaQueueItemId= */
1);
MediaItem mediaItem2 = createMediaItem(/* mediaQueueItemId= */
2);
MediaItem mediaItem3 = createMediaItem(/* mediaQueueItemId= */
3);
castPlayer.addMediaItem(mediaItem1);
updateTimeLine(ImmutableList.of(mediaItem1), /* mediaQueueItemIds= */
new int[] { 1 }, /* currentItemId= */
1);
verify(mockListener).onAvailableCommandsChanged(defaultCommands);
// Check that there were no other calls to onAvailableCommandsChanged.
verify(mockListener).onAvailableCommandsChanged(any());
castPlayer.addMediaItem(/* index= */
0, mediaItem2);
updateTimeLine(ImmutableList.of(mediaItem2, mediaItem1), /* mediaQueueItemIds= */
new int[] { 2, 1 }, /* currentItemId= */
1);
verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
castPlayer.addMediaItem(/* index= */
0, mediaItem3);
updateTimeLine(ImmutableList.of(mediaItem3, mediaItem2, mediaItem1), /* mediaQueueItemIds= */
new int[] { 3, 2, 1 }, /* currentItemId= */
1);
verify(mockListener, times(2)).onAvailableCommandsChanged(any());
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class DefaultMediaItemConverter method getPlayerConfigJson.
@Nullable
private static JSONObject getPlayerConfigJson(MediaItem mediaItem) throws JSONException {
if (mediaItem.localConfiguration == null || mediaItem.localConfiguration.drmConfiguration == null) {
return null;
}
MediaItem.DrmConfiguration drmConfiguration = mediaItem.localConfiguration.drmConfiguration;
String drmScheme;
if (C.WIDEVINE_UUID.equals(drmConfiguration.scheme)) {
drmScheme = "widevine";
} else if (C.PLAYREADY_UUID.equals(drmConfiguration.scheme)) {
drmScheme = "playready";
} else {
return null;
}
JSONObject playerConfigJson = new JSONObject();
playerConfigJson.put("withCredentials", false);
playerConfigJson.put("protectionSystem", drmScheme);
if (drmConfiguration.licenseUri != null) {
playerConfigJson.put("licenseUrl", drmConfiguration.licenseUri);
}
if (!drmConfiguration.licenseRequestHeaders.isEmpty()) {
playerConfigJson.put("headers", new JSONObject(drmConfiguration.licenseRequestHeaders));
}
return playerConfigJson;
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method clearMediaItems_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void clearMediaItems_notifiesPositionDiscontinuity() {
int[] mediaQueueItemIds = new int[] { 1, 2 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1, new int[] { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
new long[] { 20_000L, 30_000L }, /* positionMs= */
1234);
castPlayer.clearMediaItems();
updateTimeLine(/* mediaItems= */
ImmutableList.of(), /* mediaQueueItemIds= */
new int[0], /* currentItemId= */
C.INDEX_UNSET, new int[] { MediaInfo.STREAM_TYPE_BUFFERED }, /* durationsMs= */
new long[] { 20_000L }, /* positionMs= */
0);
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(), /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
1234, /* contentPositionMs= */
1234, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
null, /* windowIndex= */
0, /* mediaItem= */
null, /* periodUid= */
null, /* periodIndex= */
0, /* positionMs= */
0, /* contentPositionMs= */
0, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_REMOVE));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_REMOVE));
inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
Aggregations