Search in sources :

Example 1 with ClippingMediaSource

use of androidx.media3.exoplayer.source.ClippingMediaSource in project media by androidx.

the class ExoPlayerTest method clippedLoopedPeriodsArePlayedFully.

@Test
public void clippedLoopedPeriodsArePlayedFully() throws Exception {
    long startPositionUs = 300_000;
    long expectedDurationUs = 700_000;
    MediaSource mediaSource = new ClippingMediaSource(new FakeMediaSource(), startPositionUs, startPositionUs + expectedDurationUs);
    Clock clock = new FakeClock(/* isAutoAdvancing= */
    true);
    AtomicReference<Player> playerReference = new AtomicReference<>();
    AtomicLong positionAtDiscontinuityMs = new AtomicLong(C.TIME_UNSET);
    AtomicLong clockAtStartMs = new AtomicLong(C.TIME_UNSET);
    AtomicLong clockAtDiscontinuityMs = new AtomicLong(C.TIME_UNSET);
    Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(@Player.State int playbackState) {
            if (playbackState == Player.STATE_READY && clockAtStartMs.get() == C.TIME_UNSET) {
                clockAtStartMs.set(clock.elapsedRealtime());
            }
        }

        @Override
        public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
            if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
                positionAtDiscontinuityMs.set(playerReference.get().getCurrentPosition());
                clockAtDiscontinuityMs.set(clock.elapsedRealtime());
            }
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            playerReference.set(player);
            player.addListener(playerListener);
        }
    }).pause().setRepeatMode(Player.REPEAT_MODE_ALL).waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    1).playUntilStartOfMediaItem(/* mediaItemIndex= */
    0).setRepeatMode(Player.REPEAT_MODE_OFF).play().build();
    new ExoPlayerTestRunner.Builder(context).setClock(clock).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(positionAtDiscontinuityMs.get()).isAtLeast(0L);
    assertThat(clockAtDiscontinuityMs.get() - clockAtStartMs.get()).isAtLeast(Util.usToMs(expectedDurationUs));
}
Also used : Player(androidx.media3.common.Player) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) TransferListener(androidx.media3.datasource.TransferListener) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) Listener(androidx.media3.common.Player.Listener) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DiscontinuityReason(androidx.media3.common.Player.DiscontinuityReason) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) FakeClock(androidx.media3.test.utils.FakeClock) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeClock(androidx.media3.test.utils.FakeClock) Clock(androidx.media3.common.util.Clock) Listener(androidx.media3.common.Player.Listener) AtomicLong(java.util.concurrent.atomic.AtomicLong) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) Test(org.junit.Test)

Example 2 with ClippingMediaSource

use of androidx.media3.exoplayer.source.ClippingMediaSource in project media by androidx.

the class ExoPlayerTest method seekToUnpreparedWindowWithNonZeroOffsetInConcatenationStartsAtCorrectPosition.

@Test
public void seekToUnpreparedWindowWithNonZeroOffsetInConcatenationStartsAtCorrectPosition() throws Exception {
    FakeMediaSource mediaSource = new FakeMediaSource(/* timeline= */
    null);
    MediaSource clippedMediaSource = new ClippingMediaSource(mediaSource, /* startPositionUs= */
    3 * C.MICROS_PER_SECOND, /* endPositionUs= */
    C.TIME_END_OF_SOURCE);
    MediaSource concatenatedMediaSource = new ConcatenatingMediaSource(clippedMediaSource);
    AtomicLong positionWhenReady = new AtomicLong();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).seek(/* positionMs= */
    10).waitForPendingPlayerCommands().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline())).waitForTimelineChanged().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            positionWhenReady.set(player.getContentPosition());
        }
    }).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatedMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(positionWhenReady.get()).isEqualTo(10);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 3 with ClippingMediaSource

use of androidx.media3.exoplayer.source.ClippingMediaSource in project media by androidx.

the class ClippingMediaSourceTest method getClippedTimeline.

/**
 * Wraps the specified timeline in a {@link ClippingMediaSource} and returns the clipped timeline.
 */
private static Timeline getClippedTimeline(Timeline timeline, long durationUs) throws IOException {
    FakeMediaSource fakeMediaSource = new FakeMediaSource(timeline);
    ClippingMediaSource mediaSource = new ClippingMediaSource(fakeMediaSource, durationUs);
    return getClippedTimelines(fakeMediaSource, mediaSource)[0];
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource)

Example 4 with ClippingMediaSource

use of androidx.media3.exoplayer.source.ClippingMediaSource in project media by androidx.

the class ClippingMediaSourceTest method getClippedTimelines.

/**
 * Wraps the specified timelines in a {@link ClippingMediaSource} and returns the clipped timeline
 * for each timeline update.
 */
private static Timeline[] getClippedTimelines(long startUs, long endUs, boolean allowDynamicUpdates, boolean fromDefaultPosition, Timeline firstTimeline, Timeline... additionalTimelines) throws IOException {
    FakeMediaSource fakeMediaSource = new FakeMediaSource(firstTimeline);
    ClippingMediaSource mediaSource = new ClippingMediaSource(fakeMediaSource, startUs, endUs, /* enableInitialDiscontinuity= */
    true, allowDynamicUpdates, fromDefaultPosition);
    return getClippedTimelines(fakeMediaSource, mediaSource, additionalTimelines);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource)

Example 5 with ClippingMediaSource

use of androidx.media3.exoplayer.source.ClippingMediaSource in project media by androidx.

the class ClippingMediaSourceTest method getClippedTimelines.

private static Timeline[] getClippedTimelines(FakeMediaSource fakeMediaSource, ClippingMediaSource clippingMediaSource, Timeline... additionalTimelines) throws IOException {
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(clippingMediaSource, /* allocator= */
    null);
    Timeline[] clippedTimelines = new Timeline[additionalTimelines.length + 1];
    try {
        clippedTimelines[0] = testRunner.prepareSource();
        MediaPeriod mediaPeriod = testRunner.createPeriod(new MediaPeriodId(clippedTimelines[0].getUidOfPeriod(/* periodIndex= */
        0), /* windowSequenceNumber= */
        0));
        for (int i = 0; i < additionalTimelines.length; i++) {
            fakeMediaSource.setNewSourceInfo(additionalTimelines[i]);
            clippedTimelines[i + 1] = testRunner.assertTimelineChangeBlocking();
        }
        testRunner.releasePeriod(mediaPeriod);
        testRunner.releaseSource();
        fakeMediaSource.assertReleased();
        return clippedTimelines;
    } finally {
        testRunner.release();
    }
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)

Aggregations

FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)2 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)2 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)2 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)2 MediaSource (androidx.media3.exoplayer.source.MediaSource)2 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)2 ActionSchedule (androidx.media3.test.utils.ActionSchedule)2 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)2 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 Player (androidx.media3.common.Player)1 DiscontinuityReason (androidx.media3.common.Player.DiscontinuityReason)1 Listener (androidx.media3.common.Player.Listener)1 Timeline (androidx.media3.common.Timeline)1 Clock (androidx.media3.common.util.Clock)1 TransferListener (androidx.media3.datasource.TransferListener)1