Search in sources :

Example 6 with ClippingMediaSource

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

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(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) 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) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 7 with ClippingMediaSource

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

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)

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