use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayer method seekTo.
// We still call Listener#onSeekProcessed() for backwards compatibility with listeners that
// don't implement onPositionDiscontinuity().
@SuppressWarnings("deprecation")
@Override
public void seekTo(int mediaItemIndex, long positionMs) {
MediaStatus mediaStatus = getMediaStatus();
// We assume the default position is 0. There is no support for seeking to the default position
// in RemoteMediaClient.
positionMs = positionMs != C.TIME_UNSET ? positionMs : 0;
if (mediaStatus != null) {
if (getCurrentMediaItemIndex() != mediaItemIndex) {
remoteMediaClient.queueJumpToItem((int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null).setResultCallback(seekResultCallback);
} else {
remoteMediaClient.seek(positionMs).setResultCallback(seekResultCallback);
}
PositionInfo oldPosition = getCurrentPositionInfo();
pendingSeekCount++;
pendingSeekWindowIndex = mediaItemIndex;
pendingSeekPositionMs = positionMs;
PositionInfo newPosition = getCurrentPositionInfo();
listeners.queueEvent(Player.EVENT_POSITION_DISCONTINUITY, listener -> {
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_SEEK);
listener.onPositionDiscontinuity(oldPosition, newPosition, DISCONTINUITY_REASON_SEEK);
});
if (oldPosition.mediaItemIndex != newPosition.mediaItemIndex) {
// TODO(internal b/182261884): queue `onMediaItemTransition` event when the media item is
// repeated.
MediaItem mediaItem = getCurrentTimeline().getWindow(mediaItemIndex, window).mediaItem;
listeners.queueEvent(Player.EVENT_MEDIA_ITEM_TRANSITION, listener -> listener.onMediaItemTransition(mediaItem, MEDIA_ITEM_TRANSITION_REASON_SEEK));
}
updateAvailableCommandsAndNotifyIfChanged();
} else if (pendingSeekCount == 0) {
listeners.queueEvent(/* eventFlag= */
C.INDEX_UNSET, Listener::onSeekProcessed);
}
listeners.flushEvents();
}
use of androidx.media3.common.MediaItem in project media by androidx.
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);
}
use of androidx.media3.common.MediaItem in project media by androidx.
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());
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method addMediaItems_notifiesMediaItemTransition.
@Test
public void addMediaItems_notifiesMediaItemTransition() {
MediaItem mediaItem = createMediaItem(/* mediaQueueItemId= */
1);
List<MediaItem> mediaItems = ImmutableList.of(mediaItem);
int[] mediaQueueItemIds = new int[] { 1 };
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onMediaItemTransition(mediaItemCaptor.capture(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED));
inOrder.verify(mockListener, never()).onMediaItemTransition(any(), anyInt());
assertThat(mediaItemCaptor.getValue().localConfiguration.tag).isEqualTo(mediaItem.localConfiguration.tag);
}
use of androidx.media3.common.MediaItem in project media by androidx.
the class CastPlayerTest method isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands.
@Test
public void isCommandAvailable_duringUnseekableItem_isFalseForSeekInCurrentCommands() {
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_IN_CURRENT_MEDIA_ITEM)).isFalse();
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
Aggregations