Search in sources :

Example 11 with MediaSourceHolder

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);
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 12 with MediaSourceHolder

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();
    }
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 13 with MediaSourceHolder

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();
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 14 with MediaSourceHolder

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);
    }
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder) ArrayList(java.util.ArrayList) Handler(android.os.Handler) Nullable(androidx.annotation.Nullable) GuardedBy(androidx.annotation.GuardedBy)

Example 15 with MediaSourceHolder

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();
        }
    }
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Aggregations

MediaSourceHolder (com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)9 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 ShuffleOrder (com.google.android.exoplayer2.source.ShuffleOrder)4 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)4 FakeShuffleOrder (com.google.android.exoplayer2.testutil.FakeShuffleOrder)4 Nullable (androidx.annotation.Nullable)3 Test (org.junit.Test)3 Handler (android.os.Handler)2 AbstractConcatenatedTimeline (com.google.android.exoplayer2.AbstractConcatenatedTimeline)2 Timeline (com.google.android.exoplayer2.Timeline)2 MaskingMediaPeriod (com.google.android.exoplayer2.source.MaskingMediaPeriod)2 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)2 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)2 ArrayList (java.util.ArrayList)2 GuardedBy (androidx.annotation.GuardedBy)1 AnalyticsCollector (com.google.android.exoplayer2.analytics.AnalyticsCollector)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)1