Search in sources :

Example 1 with FakeAdaptiveMediaSource

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

the class ExoPlayerTest method loadControlNeverWantsToLoad_throwsIllegalStateException.

@Test
public void loadControlNeverWantsToLoad_throwsIllegalStateException() {
    LoadControl neverLoadingLoadControl = new DefaultLoadControl() {

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

        @Override
        public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs) {
            return true;
        }
    };
    // Use chunked data to ensure the player actually needs to continue loading and playing.
    FakeAdaptiveDataSet.Factory dataSetFactory = new FakeAdaptiveDataSet.Factory(/* chunkDurationUs= */
    500_000, /* bitratePercentStdDev= */
    10.0, new Random(0));
    MediaSource chunkedMediaSource = new FakeAdaptiveMediaSource(new FakeTimeline(), new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT)), new FakeChunkSource.Factory(dataSetFactory, new FakeDataSource.Factory()));
    ExoPlaybackException exception = assertThrows(ExoPlaybackException.class, () -> new ExoPlayerTestRunner.Builder(context).setLoadControl(neverLoadingLoadControl).setMediaSources(chunkedMediaSource).build().start().blockUntilEnded(TIMEOUT_MS));
    assertThat(exception.type).isEqualTo(ExoPlaybackException.TYPE_UNEXPECTED);
    assertThat(exception.getUnexpectedException()).isInstanceOf(IllegalStateException.class);
}
Also used : TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaSourceFactory(com.google.android.exoplayer2.testutil.FakeMediaSourceFactory) FakeAdaptiveDataSet(com.google.android.exoplayer2.testutil.FakeAdaptiveDataSet) Random(java.util.Random) 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) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeChunkSource(com.google.android.exoplayer2.testutil.FakeChunkSource) Test(org.junit.Test)

Example 2 with FakeAdaptiveMediaSource

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

the class ExoPlayerTest method loadControlNeverWantsToPlay_playbackDoesNotGetStuck.

@Test
public void loadControlNeverWantsToPlay_playbackDoesNotGetStuck() throws Exception {
    LoadControl neverLoadingOrPlayingLoadControl = new DefaultLoadControl() {

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

        @Override
        public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs) {
            return false;
        }
    };
    // Use chunked data to ensure the player actually needs to continue loading and playing.
    FakeAdaptiveDataSet.Factory dataSetFactory = new FakeAdaptiveDataSet.Factory(/* chunkDurationUs= */
    500_000, /* bitratePercentStdDev= */
    10.0, new Random(0));
    MediaSource chunkedMediaSource = new FakeAdaptiveMediaSource(new FakeTimeline(), new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT)), new FakeChunkSource.Factory(dataSetFactory, new FakeDataSource.Factory()));
    new ExoPlayerTestRunner.Builder(context).setLoadControl(neverLoadingOrPlayingLoadControl).setMediaSources(chunkedMediaSource).build().start().blockUntilEnded(TIMEOUT_MS);
}
Also used : FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaSourceFactory(com.google.android.exoplayer2.testutil.FakeMediaSourceFactory) FakeAdaptiveDataSet(com.google.android.exoplayer2.testutil.FakeAdaptiveDataSet) Random(java.util.Random) 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) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeChunkSource(com.google.android.exoplayer2.testutil.FakeChunkSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)2 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)2 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)2 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)2 MediaSource (com.google.android.exoplayer2.source.MediaSource)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)2 FakeAdaptiveDataSet (com.google.android.exoplayer2.testutil.FakeAdaptiveDataSet)2 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)2 FakeChunkSource (com.google.android.exoplayer2.testutil.FakeChunkSource)2 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)2 FakeMediaSourceFactory (com.google.android.exoplayer2.testutil.FakeMediaSourceFactory)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 Random (java.util.Random)2 Test (org.junit.Test)2 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)1 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)1