use of androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder in project media by androidx.
the class ConcatenatingMediaSource method updateMediaSourceInternal.
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) {
MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1);
int windowOffsetUpdate = timeline.getWindowCount() - (nextHolder.firstWindowIndexInChild - mediaSourceHolder.firstWindowIndexInChild);
if (windowOffsetUpdate != 0) {
correctOffsets(mediaSourceHolder.childIndex + 1, /* childIndexUpdate= */
0, windowOffsetUpdate);
}
}
scheduleTimelineUpdate();
}
use of androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder in project media by androidx.
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);
}
use of androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder in project media by androidx.
the class ConcatenatingMediaSource method addPublicMediaSources.
// Internal methods. Called from any thread.
@GuardedBy("this")
private void addPublicMediaSources(int index, Collection<MediaSource> mediaSources, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
Assertions.checkArgument((handler == null) == (onCompletionAction == null));
@Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
for (MediaSource mediaSource : mediaSources) {
Assertions.checkNotNull(mediaSource);
}
List<MediaSourceHolder> mediaSourceHolders = new ArrayList<>(mediaSources.size());
for (MediaSource mediaSource : mediaSources) {
mediaSourceHolders.add(new MediaSourceHolder(mediaSource, useLazyPreparation));
}
mediaSourcesPublic.addAll(index, mediaSourceHolders);
if (playbackThreadHandler != null && !mediaSources.isEmpty()) {
@Nullable HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
playbackThreadHandler.obtainMessage(MSG_ADD, new MessageData<>(index, mediaSourceHolders, callbackAction)).sendToTarget();
} else if (onCompletionAction != null && handler != null) {
handler.post(onCompletionAction);
}
}
use of androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder in project media by androidx.
the class ConcatenatingMediaSource method addMediaSourceInternal.
private void addMediaSourceInternal(int newIndex, MediaSourceHolder newMediaSourceHolder) {
if (newIndex > 0) {
MediaSourceHolder previousHolder = mediaSourceHolders.get(newIndex - 1);
Timeline previousTimeline = previousHolder.mediaSource.getTimeline();
newMediaSourceHolder.reset(newIndex, previousHolder.firstWindowIndexInChild + previousTimeline.getWindowCount());
} else {
newMediaSourceHolder.reset(newIndex, /* firstWindowIndexInChild= */
0);
}
Timeline newTimeline = newMediaSourceHolder.mediaSource.getTimeline();
correctOffsets(newIndex, /* childIndexUpdate= */
1, newTimeline.getWindowCount());
mediaSourceHolders.add(newIndex, newMediaSourceHolder);
mediaSourceByUid.put(newMediaSourceHolder.uid, newMediaSourceHolder);
prepareChildSource(newMediaSourceHolder, newMediaSourceHolder.mediaSource);
if (isEnabled() && mediaSourceByMediaPeriod.isEmpty()) {
enabledMediaSourceHolders.add(newMediaSourceHolder);
} else {
disableChildSource(newMediaSourceHolder);
}
}
use of androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder in project media by androidx.
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();
}
Aggregations