Search in sources :

Example 1 with MediaSourceHolder

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();
}
Also used : MediaSourceHolder(androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 2 with MediaSourceHolder

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);
}
Also used : AbstractConcatenatedTimeline(androidx.media3.exoplayer.AbstractConcatenatedTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceHolder(androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 3 with MediaSourceHolder

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

Example 4 with MediaSourceHolder

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);
    }
}
Also used : AbstractConcatenatedTimeline(androidx.media3.exoplayer.AbstractConcatenatedTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceHolder(androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 5 with MediaSourceHolder

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();
}
Also used : ShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder) FakeShuffleOrder(androidx.media3.test.utils.FakeShuffleOrder) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) Test(org.junit.Test)

Aggregations

MediaSourceHolder (androidx.media3.exoplayer.source.ConcatenatingMediaSource.MediaSourceHolder)9 Timeline (androidx.media3.common.Timeline)7 MediaSource (androidx.media3.exoplayer.source.MediaSource)5 ShuffleOrder (androidx.media3.exoplayer.source.ShuffleOrder)4 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 FakeShuffleOrder (androidx.media3.test.utils.FakeShuffleOrder)4 Nullable (androidx.annotation.Nullable)3 Test (org.junit.Test)3 Handler (android.os.Handler)2 AbstractConcatenatedTimeline (androidx.media3.exoplayer.AbstractConcatenatedTimeline)2 MaskingMediaPeriod (androidx.media3.exoplayer.source.MaskingMediaPeriod)2 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)2 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)2 ArrayList (java.util.ArrayList)2 GuardedBy (androidx.annotation.GuardedBy)1 Assertions (androidx.media3.common.util.Assertions)1 Log (androidx.media3.common.util.Log)1 Util (androidx.media3.common.util.Util)1 TransferListener (androidx.media3.datasource.TransferListener)1 AnalyticsCollector (androidx.media3.exoplayer.analytics.AnalyticsCollector)1