Search in sources :

Example 1 with TestPlayerRunHelper.runUntilTimelineChanged

use of com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilTimelineChanged in project ExoPlayer by google.

the class ExoPlayerTest method nextLoadPositionExceedingLoadControlMaxBuffer_whileCurrentLoadInProgress_doesNotThrowException.

@Test
public void nextLoadPositionExceedingLoadControlMaxBuffer_whileCurrentLoadInProgress_doesNotThrowException() throws Exception {
    long maxBufferUs = 2 * C.MICROS_PER_SECOND;
    LoadControl loadControlWithMaxBufferUs = new DefaultLoadControl() {

        @Override
        public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
            return bufferedDurationUs < maxBufferUs;
        }

        @Override
        public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs) {
            return true;
        }
    };
    MediaSource mediaSourceWithLoadInProgress = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            return new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher) {

                @Override
                public long getBufferedPositionUs() {
                    // Pretend not to have buffered data yet.
                    return 0;
                }

                @Override
                public long getNextLoadPositionUs() {
                    // Set next load position beyond the maxBufferUs configured in the LoadControl.
                    return Long.MAX_VALUE;
                }

                @Override
                public boolean isLoading() {
                    return true;
                }
            };
        }
    };
    FakeRenderer rendererWaitingForData = new FakeRenderer(C.TRACK_TYPE_VIDEO) {

        @Override
        public boolean isReady() {
            return false;
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(rendererWaitingForData).setLoadControl(loadControlWithMaxBufferUs).build();
    player.setMediaSource(mediaSourceWithLoadInProgress);
    player.prepare();
    // Wait until the MediaSource is prepared, i.e. returned its timeline, and at least one
    // iteration of doSomeWork after this was run.
    TestPlayerRunHelper.runUntilTimelineChanged(player);
    runUntilPendingCommandsAreFullyHandled(player);
    assertThat(player.getPlayerError()).isNull();
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) 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) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

Nullable (androidx.annotation.Nullable)1 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)1 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)1 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)1 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)1 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)1 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)1 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)1 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)1 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)1 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)1 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)1 Allocator (com.google.android.exoplayer2.upstream.Allocator)1 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)1 Test (org.junit.Test)1