Search in sources :

Example 1 with FakeAdaptiveMediaSource

use of androidx.media3.test.utils.FakeAdaptiveMediaSource in project media by androidx.

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(androidx.media3.test.utils.FakeAdaptiveMediaSource) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeMediaSourceFactory(androidx.media3.test.utils.FakeMediaSourceFactory) FakeAdaptiveDataSet(androidx.media3.test.utils.FakeAdaptiveDataSet) Random(java.util.Random) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TrackGroup(androidx.media3.common.TrackGroup) FakeChunkSource(androidx.media3.test.utils.FakeChunkSource) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 2 with FakeAdaptiveMediaSource

use of androidx.media3.test.utils.FakeAdaptiveMediaSource in project media by androidx.

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(androidx.media3.test.utils.TestExoPlayerBuilder) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeMediaSourceFactory(androidx.media3.test.utils.FakeMediaSourceFactory) FakeAdaptiveDataSet(androidx.media3.test.utils.FakeAdaptiveDataSet) Random(java.util.Random) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TrackGroup(androidx.media3.common.TrackGroup) FakeChunkSource(androidx.media3.test.utils.FakeChunkSource) Test(org.junit.Test)

Aggregations

TrackGroup (androidx.media3.common.TrackGroup)2 TrackGroupArray (androidx.media3.common.TrackGroupArray)2 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)2 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)2 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)2 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)2 MediaSource (androidx.media3.exoplayer.source.MediaSource)2 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)2 FakeAdaptiveDataSet (androidx.media3.test.utils.FakeAdaptiveDataSet)2 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)2 FakeChunkSource (androidx.media3.test.utils.FakeChunkSource)2 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)2 FakeMediaSourceFactory (androidx.media3.test.utils.FakeMediaSourceFactory)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 Random (java.util.Random)2 Test (org.junit.Test)2 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)1 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)1