Search in sources :

Example 1 with ClippingMediaSource

use of com.google.android.exoplayer2.source.ClippingMediaSource in project ExoPlayer by google.

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 : PlaceholderTimeline(com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)

Example 2 with ClippingMediaSource

use of com.google.android.exoplayer2.source.ClippingMediaSource in project Signal-Android by signalapp.

the class VideoPlayer method clip.

public void clip(long fromUs, long toUs, boolean playWhenReady) {
    if (this.exoPlayer != null && mediaItem != null) {
        MediaSource mediaItemSource = mediaSourceFactory.createMediaSource(mediaItem);
        ClippingMediaSource clippedSource = new ClippingMediaSource(mediaItemSource, fromUs, toUs);
        exoPlayer.setMediaSource(clippedSource);
        exoPlayer.prepare();
        exoPlayer.setPlayWhenReady(playWhenReady);
        clipped = true;
        clippedStartUs = fromUs;
    }
}
Also used : ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource)

Example 3 with ClippingMediaSource

use of com.google.android.exoplayer2.source.ClippingMediaSource in project ExoPlayer by google.

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(com.google.android.exoplayer2.testutil.FakeMediaSource)

Example 4 with ClippingMediaSource

use of com.google.android.exoplayer2.source.ClippingMediaSource in project ExoPlayer by google.

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(com.google.android.exoplayer2.testutil.FakeMediaSource)

Example 5 with ClippingMediaSource

use of com.google.android.exoplayer2.source.ClippingMediaSource in project ExoPlayer by google.

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 : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DiscontinuityReason(com.google.android.exoplayer2.Player.DiscontinuityReason) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) Clock(com.google.android.exoplayer2.util.Clock) Listener(com.google.android.exoplayer2.Player.Listener) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) Test(org.junit.Test)

Aggregations

ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)4 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)2 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)2 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)2 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)2 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)2 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)2 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 DiscontinuityReason (com.google.android.exoplayer2.Player.DiscontinuityReason)1 Listener (com.google.android.exoplayer2.Player.Listener)1 Timeline (com.google.android.exoplayer2.Timeline)1 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 PlaceholderTimeline (com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline)1