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();
}
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);
}
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();
}
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();
}
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);
}
Aggregations