use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class ConcatenatingMediaSource method releasePeriod.
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
MediaSourceHolder holder = Assertions.checkNotNull(mediaSourceByMediaPeriod.remove(mediaPeriod));
holder.mediaSource.releasePeriod(mediaPeriod);
holder.activeMediaPeriodIds.remove(((MaskingMediaPeriod) mediaPeriod).id);
if (!mediaSourceByMediaPeriod.isEmpty()) {
disableUnusedMediaSources();
}
maybeReleaseChildSource(holder);
}
use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class ConcatenatingMediaSource method moveMediaSourceInternal.
private void moveMediaSourceInternal(int currentIndex, int newIndex) {
int startIndex = min(currentIndex, newIndex);
int endIndex = max(currentIndex, newIndex);
int windowOffset = mediaSourceHolders.get(startIndex).firstWindowIndexInChild;
mediaSourceHolders.add(newIndex, mediaSourceHolders.remove(currentIndex));
for (int i = startIndex; i <= endIndex; i++) {
MediaSourceHolder holder = mediaSourceHolders.get(i);
holder.childIndex = i;
holder.firstWindowIndexInChild = windowOffset;
windowOffset += holder.mediaSource.getTimeline().getWindowCount();
}
}
use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
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 com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
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 com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class ConcatenatingMediaSource method disableUnusedMediaSources.
private void disableUnusedMediaSources() {
Iterator<MediaSourceHolder> iterator = enabledMediaSourceHolders.iterator();
while (iterator.hasNext()) {
MediaSourceHolder holder = iterator.next();
if (holder.activeMediaPeriodIds.isEmpty()) {
disableChildSource(holder);
iterator.remove();
}
}
}
Aggregations