Search in sources :

Example 6 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaSourceListTest method release_mediaSourceListPrepared_expectSourcesReleasedNotRemoved.

@Test
public void release_mediaSourceListPrepared_expectSourcesReleasedNotRemoved() {
    MediaSource mockMediaSource = mock(MediaSource.class);
    when(mockMediaSource.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSourceList.MediaSourceHolder mediaSourceHolder = new MediaSourceList.MediaSourceHolder(mockMediaSource, /* useLazyPreparation= */
    false);
    mediaSourceList.prepare(/* mediaTransferListener= */
    null);
    mediaSourceList.setMediaSources(Collections.singletonList(mediaSourceHolder), new ShuffleOrder.DefaultShuffleOrder(/* length= */
    1));
    verify(mockMediaSource, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
    isNull(), any());
    mediaSourceList.release();
    verify(mockMediaSource, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSourceHolder.isRemoved).isFalse();
}
Also used : ShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Test(org.junit.Test)

Example 7 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaPeriodQueueTest method setupTimeline.

private void setupTimeline(Timeline timeline) {
    fakeMediaSource = new FakeMediaSource(timeline);
    MediaSourceList.MediaSourceHolder mediaSourceHolder = new MediaSourceList.MediaSourceHolder(fakeMediaSource, /* useLazyPreparation= */
    false);
    mediaSourceList.setMediaSources(ImmutableList.of(mediaSourceHolder), new FakeShuffleOrder(/* length= */
    1));
    mediaSourceHolder.mediaSource.prepareSource(mock(MediaSourceCaller.class), /* mediaTransferListener */
    null, PlayerId.UNSET);
    Timeline playlistTimeline = mediaSourceList.createTimeline();
    firstPeriodUid = playlistTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    playbackInfo = new PlaybackInfo(playlistTimeline, mediaPeriodQueue.resolveMediaPeriodIdForAds(playlistTimeline, firstPeriodUid, /* positionUs= */
    0), /* requestedContentPositionUs= */
    C.TIME_UNSET, /* discontinuityStartPositionUs= */
    0, Player.STATE_READY, /* playbackError= */
    null, /* isLoading= */
    false, /* trackGroups= */
    null, /* trackSelectorResult= */
    null, /* staticMetadata= */
    ImmutableList.of(), /* loadingMediaPeriodId= */
    null, /* playWhenReady= */
    false, Player.PLAYBACK_SUPPRESSION_REASON_NONE, /* playbackParameters= */
    PlaybackParameters.DEFAULT, /* bufferedPositionUs= */
    0, /* totalBufferedDurationUs= */
    0, /* positionUs= */
    0, /* offloadSchedulingEnabled= */
    false, /* sleepingForOffload= */
    false);
}
Also used : MediaSourceCaller(com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder)

Example 8 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaSourceListTest method setMediaSources_mediaSourceListUnprepared_notUsingLazyPreparation.

@Test
public void setMediaSources_mediaSourceListUnprepared_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);
    Timeline timeline = mediaSourceList.setMediaSources(mediaSources, shuffleOrder);
    assertThat(timeline.getWindowCount()).isEqualTo(2);
    assertThat(mediaSourceList.getSize()).isEqualTo(2);
    // Assert holder offsets have been set properly
    for (int i = 0; i < mediaSources.size(); i++) {
        MediaSourceList.MediaSourceHolder mediaSourceHolder = mediaSources.get(i);
        assertThat(mediaSourceHolder.isRemoved).isFalse();
        assertThat(mediaSourceHolder.firstWindowIndexInChild).isEqualTo(i);
    }
    // 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));
    timeline = mediaSourceList.setMediaSources(moreMediaSources, shuffleOrder);
    assertThat(mediaSourceList.getSize()).isEqualTo(2);
    assertThat(timeline.getWindowCount()).isEqualTo(2);
    for (int i = 0; i < moreMediaSources.size(); i++) {
        MediaSourceList.MediaSourceHolder mediaSourceHolder = moreMediaSources.get(i);
        assertThat(mediaSourceHolder.isRemoved).isFalse();
        assertThat(mediaSourceHolder.firstWindowIndexInChild).isEqualTo(i);
    }
    // Expect removed holders and sources to be removed without releasing.
    verify(mockMediaSource1, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSources.get(0).isRemoved).isTrue();
    // Expect re-used holder and source not to be removed.
    verify(mockMediaSource2, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSources.get(1).isRemoved).isFalse();
}
Also used : ShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Test(org.junit.Test)

Example 9 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaSourceListTest method release_mediaSourceListUnprepared_expectSourcesNotReleased.

@Test
public void release_mediaSourceListUnprepared_expectSourcesNotReleased() {
    MediaSource mockMediaSource = mock(MediaSource.class);
    when(mockMediaSource.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
    MediaSourceList.MediaSourceHolder mediaSourceHolder = new MediaSourceList.MediaSourceHolder(mockMediaSource, /* useLazyPreparation= */
    false);
    mediaSourceList.setMediaSources(Collections.singletonList(mediaSourceHolder), new ShuffleOrder.DefaultShuffleOrder(/* length= */
    1));
    verify(mockMediaSource, times(0)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
    isNull(), any());
    mediaSourceList.release();
    verify(mockMediaSource, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
    assertThat(mediaSourceHolder.isRemoved).isFalse();
}
Also used : ShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) MediaSource(com.google.android.exoplayer2.source.MediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Test(org.junit.Test)

Example 10 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class ConcatenatingMediaSource method removeMediaSourceInternal.

private void removeMediaSourceInternal(int index) {
    MediaSourceHolder holder = mediaSourceHolders.remove(index);
    mediaSourceByUid.remove(holder.uid);
    Timeline oldTimeline = holder.mediaSource.getTimeline();
    correctOffsets(index, /* childIndexUpdate= */
    -1, -oldTimeline.getWindowCount());
    holder.isRemoved = true;
    maybeReleaseChildSource(holder);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) AbstractConcatenatedTimeline(com.google.android.exoplayer2.AbstractConcatenatedTimeline) MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Aggregations

MediaSourceHolder (com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)9 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 ShuffleOrder (com.google.android.exoplayer2.source.ShuffleOrder)4 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)4 FakeShuffleOrder (com.google.android.exoplayer2.testutil.FakeShuffleOrder)4 Nullable (androidx.annotation.Nullable)3 Test (org.junit.Test)3 Handler (android.os.Handler)2 AbstractConcatenatedTimeline (com.google.android.exoplayer2.AbstractConcatenatedTimeline)2 Timeline (com.google.android.exoplayer2.Timeline)2 MaskingMediaPeriod (com.google.android.exoplayer2.source.MaskingMediaPeriod)2 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)2 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)2 ArrayList (java.util.ArrayList)2 GuardedBy (androidx.annotation.GuardedBy)1 AnalyticsCollector (com.google.android.exoplayer2.analytics.AnalyticsCollector)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)1