Search in sources :

Example 6 with MediaItem

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();
}
Also used : MediaItem(androidx.media3.common.MediaItem) MediaStatus(com.google.android.gms.cast.MediaStatus)

Example 7 with MediaItem

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);
}
Also used : MediaItem(androidx.media3.common.MediaItem)

Example 8 with MediaItem

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());
}
Also used : Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 9 with MediaItem

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);
}
Also used : InOrder(org.mockito.InOrder) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 10 with MediaItem

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();
}
Also used : 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