Search in sources :

Example 1 with ShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder in project media by androidx.

the class ExoPlayerImpl method addMediaSources.

@Override
public void addMediaSources(int index, List<MediaSource> mediaSources) {
    verifyApplicationThread();
    Assertions.checkArgument(index >= 0);
    Timeline oldTimeline = getCurrentTimeline();
    pendingOperationAcks++;
    List<MediaSourceList.MediaSourceHolder> holders = addMediaSourceHolders(index, mediaSources);
    Timeline newTimeline = createMaskingTimeline();
    PlaybackInfo newPlaybackInfo = maskTimelineAndPosition(playbackInfo, newTimeline, getPeriodPositionUsAfterTimelineChanged(oldTimeline, newTimeline));
    internalPlayer.addMediaSources(index, holders, shuffleOrder);
    updatePlaybackInfo(newPlaybackInfo, /* timelineChangeReason= */
    TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* ignored */
    PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, /* seekProcessed= */
    false, /* positionDiscontinuity= */
    false, /* ignored */
    DISCONTINUITY_REASON_INTERNAL, /* ignored */
    C.TIME_UNSET, /* ignored */
    C.INDEX_UNSET);
}
Also used : Timeline(androidx.media3.common.Timeline)

Example 2 with ShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder in project media by androidx.

the class ExoPlayerImpl method moveMediaItems.

@Override
public void moveMediaItems(int fromIndex, int toIndex, int newFromIndex) {
    verifyApplicationThread();
    Assertions.checkArgument(fromIndex >= 0 && fromIndex <= toIndex && toIndex <= mediaSourceHolderSnapshots.size() && newFromIndex >= 0);
    Timeline oldTimeline = getCurrentTimeline();
    pendingOperationAcks++;
    newFromIndex = min(newFromIndex, mediaSourceHolderSnapshots.size() - (toIndex - fromIndex));
    Util.moveItems(mediaSourceHolderSnapshots, fromIndex, toIndex, newFromIndex);
    Timeline newTimeline = createMaskingTimeline();
    PlaybackInfo newPlaybackInfo = maskTimelineAndPosition(playbackInfo, newTimeline, getPeriodPositionUsAfterTimelineChanged(oldTimeline, newTimeline));
    internalPlayer.moveMediaSources(fromIndex, toIndex, newFromIndex, shuffleOrder);
    updatePlaybackInfo(newPlaybackInfo, /* timelineChangeReason= */
    TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* ignored */
    PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, /* seekProcessed= */
    false, /* positionDiscontinuity= */
    false, /* ignored */
    DISCONTINUITY_REASON_INTERNAL, /* ignored */
    C.TIME_UNSET, /* ignored */
    C.INDEX_UNSET);
}
Also used : Timeline(androidx.media3.common.Timeline)

Example 3 with ShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder in project media by androidx.

the class MediaSourceListTest method setMediaSources_mediaSourceListPrepared_notUsingLazyPreparation.

@Test
public void setMediaSources_mediaSourceListPrepared_notUsingLazyPreparation() {
    ShuffleOrder.DefaultShuffleOrder shuffleOrder = new ShuffleOrder.DefaultShuffleOrder(/* length= */
    2);
    MediaSource mockMediaSource1 = mock(MediaSource.class);
    when(mockMediaSource1.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSource mockMediaSource2 = mock(MediaSource.class);
    when(mockMediaSource2.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    List<MediaSourceList.MediaSourceHolder> mediaSources = createFakeHoldersWithSources(/* useLazyPreparation= */
    false, mockMediaSource1, mockMediaSource2);
    mediaSourceList.prepare(/* mediaTransferListener= */
    null);
    mediaSourceList.setMediaSources(mediaSources, shuffleOrder);
    // Verify sources are prepared.
    verify(mockMediaSource1, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
    isNull(), any());
    verify(mockMediaSource2, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
    isNull(), any());
    // Set media items again. The second holder is re-used.
    MediaSource mockMediaSource3 = mock(MediaSource.class);
    when(mockMediaSource3.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    List<MediaSourceList.MediaSourceHolder> moreMediaSources = createFakeHoldersWithSources(/* useLazyPreparation= */
    false, mockMediaSource3);
    moreMediaSources.add(mediaSources.get(1));
    mediaSourceList.setMediaSources(moreMediaSources, shuffleOrder);
    // Expect removed holders and sources to be removed and released.
    verify(mockMediaSource1, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSources.get(0).isRemoved).isTrue();
    // Expect re-used holder and source not to be removed but released.
    verify(mockMediaSource2, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSources.get(1).isRemoved).isFalse();
    verify(mockMediaSource2, times(2)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
    isNull(), any());
}
Also used : ShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) Test(org.junit.Test)

Example 4 with ShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder in project media by androidx.

the class MediaSourceListTest method removeMediaSourceRange_expectTimelineUsesCustomShuffleOrder.

@Test
public void removeMediaSourceRange_expectTimelineUsesCustomShuffleOrder() {
    ShuffleOrder shuffleOrder = new ShuffleOrder.DefaultShuffleOrder(/* length= */
    MEDIA_SOURCE_LIST_SIZE);
    mediaSourceList.addMediaSources(/* index= */
    0, createFakeHolders(), shuffleOrder);
    Timeline timeline = mediaSourceList.removeMediaSourceRange(/* fromIndex= */
    0, /* toIndex= */
    2, new FakeShuffleOrder(/* length= */
    2));
    assertTimelineUsesFakeShuffleOrder(timeline);
}
Also used : ShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Timeline(androidx.media3.common.Timeline) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) Test(org.junit.Test)

Example 5 with ShuffleOrder

use of androidx.media3.exoplayer.source.ShuffleOrder in project media by androidx.

the class MediaSourceListTest method removeMediaSources_whenPrepared_expectRelease.

@Test
public void removeMediaSources_whenPrepared_expectRelease() {
    MediaSource mockMediaSource1 = mock(MediaSource.class);
    when(mockMediaSource1.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSource mockMediaSource2 = mock(MediaSource.class);
    when(mockMediaSource2.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSource mockMediaSource3 = mock(MediaSource.class);
    when(mockMediaSource3.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSource mockMediaSource4 = mock(MediaSource.class);
    when(mockMediaSource4.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    ShuffleOrder.DefaultShuffleOrder shuffleOrder = new ShuffleOrder.DefaultShuffleOrder(/* length= */
    4);
    List<MediaSourceList.MediaSourceHolder> holders = createFakeHoldersWithSources(/* useLazyPreparation= */
    false, mockMediaSource1, mockMediaSource2, mockMediaSource3, mockMediaSource4);
    mediaSourceList.prepare(/* mediaTransferListener */
    null);
    mediaSourceList.addMediaSources(/* index= */
    0, holders, shuffleOrder);
    mediaSourceList.removeMediaSourceRange(/* fromIndex= */
    1, /* toIndex= */
    3, shuffleOrder);
    assertThat(mediaSourceList.getSize()).isEqualTo(2);
    holders.remove(2);
    holders.remove(1);
    assertDefaultFirstWindowInChildIndexOrder(holders);
    verify(mockMediaSource1, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    verify(mockMediaSource2, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    verify(mockMediaSource3, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    verify(mockMediaSource4, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
}
Also used : ShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) Test(org.junit.Test)

Aggregations

Timeline (androidx.media3.common.Timeline)14 Test (org.junit.Test)11 ShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder)9 FakeShuffleOrder (androidx.media3.test.utils.FakeShuffleOrder)9 MediaSource (androidx.media3.exoplayer.source.MediaSource)5 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)5 DefaultShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder)4 UnshuffledShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder.UnshuffledShuffleOrder)4 SuppressLint (android.annotation.SuppressLint)2 IllegalSeekPositionException (androidx.media3.common.IllegalSeekPositionException)1 AbstractConcatenatedTimeline (androidx.media3.exoplayer.AbstractConcatenatedTimeline)1