use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class ExoPlayerTest method timelineUpdateWithNewMidrollAdCuePoint_dropsPrebufferedPeriod.
@Test
public void timelineUpdateWithNewMidrollAdCuePoint_dropsPrebufferedPeriod() throws Exception {
Timeline timeline1 = new FakeTimeline(TimelineWindowDefinition.createPlaceholder(/* tag= */
0));
AdPlaybackState adPlaybackStateWithMidroll = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 5 * C.MICROS_PER_SECOND);
Timeline timeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
10_000_000, adPlaybackStateWithMidroll));
FakeMediaSource mediaSource = new FakeMediaSource(timeline1, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2)).waitForTimelineChanged(timeline2, /* expectedReason= */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
testRunner.assertPlayedPeriodIndices(0);
testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_AUTO_TRANSITION, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
assertThat(mediaSource.getCreatedMediaPeriods()).hasSize(4);
assertThat(mediaSource.getCreatedMediaPeriods().get(0).nextAdGroupIndex).isEqualTo(C.INDEX_UNSET);
assertThat(mediaSource.getCreatedMediaPeriods().get(1).nextAdGroupIndex).isEqualTo(0);
assertThat(mediaSource.getCreatedMediaPeriods().get(2).adGroupIndex).isEqualTo(0);
assertThat(mediaSource.getCreatedMediaPeriods().get(3).adGroupIndex).isEqualTo(C.INDEX_UNSET);
}
use of com.google.android.exoplayer2.source.MediaSource 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();
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class MediaSourceListTest method prepareAndReprepareAfterRelease_expectSourcePreparationAfterMediaSourceListPrepare.
@Test
public void prepareAndReprepareAfterRelease_expectSourcePreparationAfterMediaSourceListPrepare() {
MediaSource mockMediaSource1 = mock(MediaSource.class);
when(mockMediaSource1.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
MediaSource mockMediaSource2 = mock(MediaSource.class);
when(mockMediaSource2.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
mediaSourceList.setMediaSources(createFakeHoldersWithSources(/* useLazyPreparation= */
false, mockMediaSource1, mockMediaSource2), new ShuffleOrder.DefaultShuffleOrder(/* length= */
2));
// Verify prepare is called once on prepare.
verify(mockMediaSource1, times(0)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
verify(mockMediaSource2, times(0)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
mediaSourceList.prepare(/* mediaTransferListener= */
null);
assertThat(mediaSourceList.isPrepared()).isTrue();
// Verify prepare is called once on prepare.
verify(mockMediaSource1, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
verify(mockMediaSource2, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
mediaSourceList.release();
mediaSourceList.prepare(/* mediaTransferListener= */
null);
// Verify prepare is called a second time on re-prepare.
verify(mockMediaSource1, times(2)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
verify(mockMediaSource2, times(2)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class MediaSourceListTest method clearMediaSourceList_expectSourcesReleasedAndRemoved.
@Test
public void clearMediaSourceList_expectSourcesReleasedAndRemoved() {
ShuffleOrder.DefaultShuffleOrder shuffleOrder = new ShuffleOrder.DefaultShuffleOrder(/* length= */
4);
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> holders = createFakeHoldersWithSources(/* useLazyPreparation= */
false, mockMediaSource1, mockMediaSource2);
mediaSourceList.setMediaSources(holders, shuffleOrder);
mediaSourceList.prepare(/* mediaTransferListener= */
null);
Timeline timeline = mediaSourceList.clear(shuffleOrder);
assertThat(timeline.isEmpty()).isTrue();
assertThat(holders.get(0).isRemoved).isTrue();
assertThat(holders.get(1).isRemoved).isTrue();
verify(mockMediaSource1, times(1)).releaseSource(any());
verify(mockMediaSource2, times(1)).releaseSource(any());
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class MediaSourceListTest method addMediaSources_mediaSourceListPrepared_notUsingLazyPreparation_expectPrepared.
@Test
public void addMediaSources_mediaSourceListPrepared_notUsingLazyPreparation_expectPrepared() {
MediaSource mockMediaSource1 = mock(MediaSource.class);
when(mockMediaSource1.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
MediaSource mockMediaSource2 = mock(MediaSource.class);
when(mockMediaSource2.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
mediaSourceList.prepare(/* mediaTransferListener= */
null);
mediaSourceList.addMediaSources(/* index= */
0, createFakeHoldersWithSources(/* useLazyPreparation= */
false, mockMediaSource1, mockMediaSource2), new ShuffleOrder.DefaultShuffleOrder(/* length= */
2));
// Verify prepare is called on sources when added.
verify(mockMediaSource1, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
verify(mockMediaSource2, times(1)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
}
Aggregations