use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
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 com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class ConcatenatingMediaSource method createPeriod.
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
@Nullable MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
if (holder == null) {
// Stale event. The media source has already been removed.
holder = new MediaSourceHolder(new FakeMediaSource(), useLazyPreparation);
holder.isRemoved = true;
prepareChildSource(holder, holder.mediaSource);
}
enableMediaSource(holder);
holder.activeMediaPeriodIds.add(childMediaPeriodId);
MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
mediaSourceByMediaPeriod.put(mediaPeriod, holder);
disableUnusedMediaSources();
return mediaPeriod;
}
use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class ConcatenatingMediaSource method correctOffsets.
private void correctOffsets(int startIndex, int childIndexUpdate, int windowOffsetUpdate) {
// the childIndex and firstWindowIndexInChild variables.
for (int i = startIndex; i < mediaSourceHolders.size(); i++) {
MediaSourceHolder holder = mediaSourceHolders.get(i);
holder.childIndex += childIndexUpdate;
holder.firstWindowIndexInChild += windowOffsetUpdate;
}
}
use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class MediaSourceList method prepareChildSource.
private void prepareChildSource(MediaSourceHolder holder) {
MediaSource mediaSource = holder.mediaSource;
MediaSource.MediaSourceCaller caller = (source, timeline) -> mediaSourceListInfoListener.onPlaylistUpdateRequested();
ForwardingEventListener eventListener = new ForwardingEventListener(holder);
childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener));
mediaSource.addEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
mediaSource.addDrmEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
mediaSource.prepareSource(caller, mediaTransferListener, playerId);
}
use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.
the class MediaSourceList method createPeriod.
/**
* Returns a new {@link MediaPeriod} identified by {@code periodId}.
*
* @param id The identifier of the period.
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
* @param startPositionUs The expected start position, in microseconds.
* @return A new {@link MediaPeriod}.
*/
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs) {
Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
MediaSource.MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
MediaSourceHolder holder = Assertions.checkNotNull(mediaSourceByUid.get(mediaSourceHolderUid));
enableMediaSource(holder);
holder.activeMediaPeriodIds.add(childMediaPeriodId);
MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
mediaSourceByMediaPeriod.put(mediaPeriod, holder);
disableUnusedMediaSources();
return mediaPeriod;
}
Aggregations