Search in sources :

Example 11 with FakeMediaPeriod

use of com.google.android.exoplayer2.testutil.FakeMediaPeriod in project ExoPlayer by google.

the class ExoPlayerTest method seekDiscontinuityWithAdjustment.

@Test
public void seekDiscontinuityWithAdjustment() throws Exception {
    FakeTimeline timeline = new FakeTimeline(1);
    FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            false);
            mediaPeriod.setSeekToUsOffset(10);
            return mediaPeriod;
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).seek(10).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT);
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 12 with FakeMediaPeriod

use of com.google.android.exoplayer2.testutil.FakeMediaPeriod in project ExoPlayer by google.

the class ExoPlayerTest method internalDiscontinuityAtInitialPosition.

@Test
public void internalDiscontinuityAtInitialPosition() throws Exception {
    FakeTimeline timeline = new FakeTimeline();
    FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher);
            // Set a discontinuity at the position this period is supposed to start at anyway.
            mediaPeriod.setDiscontinuityPositionUs(timeline.getWindow(/* windowIndex= */
            0, new Window()).positionInFirstPeriodUs);
            return mediaPeriod;
        }
    };
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).build().start().blockUntilEnded(TIMEOUT_MS);
    // If the position is unchanged we do not expect the discontinuity to be reported externally.
    testRunner.assertNoPositionDiscontinuities();
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Window(com.google.android.exoplayer2.Timeline.Window) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)12 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)12 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)12 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)12 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)12 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)12 Allocator (com.google.android.exoplayer2.upstream.Allocator)12 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)12 Nullable (androidx.annotation.Nullable)11 Test (org.junit.Test)11 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)9 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)6 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)5 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)5 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)5 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)5 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)5 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)5 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)5