Search in sources :

Example 1 with ActionSchedule

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

the class ExoPlayerTest method setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled.

@Test
public void setUnsupportedPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndResetsOnceHandled() throws Exception {
    Renderer renderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        public long getPositionUs() {
            return 0;
        }

        @Override
        public void setPlaybackParameters(PlaybackParameters playbackParameters) {
        }

        @Override
        public PlaybackParameters getPlaybackParameters() {
            return PlaybackParameters.DEFAULT;
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.1f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.2f)).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.3f)).play().build();
    List<PlaybackParameters> reportedPlaybackParameters = new ArrayList<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            reportedPlaybackParameters.add(playbackParameters);
        }
    };
    new ExoPlayerTestRunner.Builder(context).setSupportedFormats(ExoPlayerTestRunner.AUDIO_FORMAT).setRenderers(renderer).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(reportedPlaybackParameters).containsExactly(new PlaybackParameters(/* speed= */
    1.1f), new PlaybackParameters(/* speed= */
    1.2f), new PlaybackParameters(/* speed= */
    1.3f), PlaybackParameters.DEFAULT).inOrder();
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) AnalyticsListener(androidx.media3.exoplayer.analytics.AnalyticsListener) TransferListener(androidx.media3.datasource.TransferListener) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) Listener(androidx.media3.common.Player.Listener) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) ActionSchedule(androidx.media3.test.utils.ActionSchedule) FakeRenderer(androidx.media3.test.utils.FakeRenderer) FakeVideoRenderer(androidx.media3.test.utils.FakeVideoRenderer) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) ArrayList(java.util.ArrayList) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) PlaybackParameters(androidx.media3.common.PlaybackParameters) Test(org.junit.Test)

Example 2 with ActionSchedule

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

the class ExoPlayerTest method cancelRepeatedMessageAfterDelivery.

@Test
public void cancelRepeatedMessageAfterDelivery() throws Exception {
    final CountingMessageTarget target = new CountingMessageTarget();
    final AtomicReference<PlayerMessage> message = new AtomicReference<>();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            message.set(player.createMessage(target).setPosition(/* positionMs= */
            50).setDeleteAfterDelivery(/* deleteAfterDelivery= */
            false).send());
        }
    }).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    51).seek(/* positionMs= */
    0).executeRunnable(() -> message.get().cancel()).play().build();
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(message.get().isCanceled()).isTrue();
    assertThat(target.messageCount).isEqualTo(1);
}
Also used : ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 with ActionSchedule

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

the class ExoPlayerTest method setMediaSources_whenEmpty_invalidInitialSeek_correctMasking.

@Test
public void setMediaSources_whenEmpty_invalidInitialSeek_correctMasking() throws Exception {
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] currentPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    final long[] bufferedPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPositionDiscontinuity().waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPositions[0] = player.getCurrentPosition();
            bufferedPositions[0] = player.getBufferedPosition();
            // Increase current media item index.
            player.addMediaSource(/* index= */
            0, new FakeMediaSource());
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
            currentPositions[1] = player.getCurrentPosition();
            bufferedPositions[1] = player.getBufferedPosition();
        }
    }).prepare().waitForTimelineChanged().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
            currentPositions[2] = player.getCurrentPosition();
            bufferedPositions[2] = player.getBufferedPosition();
        }
    }).waitForPlaybackState(Player.STATE_ENDED).build();
    new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, 2000).setMediaSources(new FakeMediaSource()).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 0, 1, 1 }, currentMediaItemIndices);
    assertArrayEquals(new long[] { 0, 0, 0 }, currentPositions);
    assertArrayEquals(new long[] { 0, 0, 0 }, bufferedPositions);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Test(org.junit.Test)

Example 4 with ActionSchedule

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

the class ExoPlayerTest method setPlaybackSpeedBeforePreparationCompletesSucceeds.

@Test
public void setPlaybackSpeedBeforePreparationCompletesSucceeds() throws Exception {
    // Test that no exception is thrown when playback parameters are updated between creating a
    // period and preparation of the period completing.
    final CountDownLatch createPeriodCalledCountDownLatch = new CountDownLatch(1);
    final FakeMediaPeriod[] fakeMediaPeriodHolder = new FakeMediaPeriod[1];
    MediaSource mediaSource = 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) {
            // Defer completing preparation of the period until playback parameters have been set.
            fakeMediaPeriodHolder[0] = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            true);
            createPeriodCalledCountDownLatch.countDown();
            return fakeMediaPeriodHolder[0];
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            try {
                player.getClock().onThreadBlocked();
                createPeriodCalledCountDownLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        }
    }).setPlaybackParameters(new PlaybackParameters(/* speed= */
    2f)).executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Allocator(androidx.media3.exoplayer.upstream.Allocator) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) TrackGroupArray(androidx.media3.common.TrackGroupArray) CountDownLatch(java.util.concurrent.CountDownLatch) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) 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) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) PlaybackParameters(androidx.media3.common.PlaybackParameters) Test(org.junit.Test)

Example 5 with ActionSchedule

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

the class ExoPlayerTest method runPositionMaskingCapturingActionSchedule.

private void runPositionMaskingCapturingActionSchedule(PlayerRunnable actionRunnable, int pauseMediaItemIndex, int[] mediaItemIndex, long[] positionMs, long[] bufferedPosition, long[] totalBufferedDuration, MediaSource... mediaSources) throws Exception {
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).playUntilPosition(pauseMediaItemIndex, /* positionMs= */
    8000).executeRunnable(actionRunnable).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndex[0] = player.getCurrentMediaItemIndex();
            positionMs[0] = player.getCurrentPosition();
            bufferedPosition[0] = player.getBufferedPosition();
            totalBufferedDuration[0] = player.getTotalBufferedDuration();
        }
    }).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndex[1] = player.getCurrentMediaItemIndex();
            positionMs[1] = player.getCurrentPosition();
            bufferedPosition[1] = player.getBufferedPosition();
            totalBufferedDuration[1] = player.getTotalBufferedDuration();
        }
    }).stop().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSources).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
}
Also used : ActionSchedule(androidx.media3.test.utils.ActionSchedule) PlayerRunnable(androidx.media3.test.utils.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder)

Aggregations

ActionSchedule (androidx.media3.test.utils.ActionSchedule)143 Test (org.junit.Test)142 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)103 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)97 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)96 FakeTimeline (androidx.media3.test.utils.FakeTimeline)84 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)79 Timeline (androidx.media3.common.Timeline)64 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)59 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)59 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)55 MediaSource (androidx.media3.exoplayer.source.MediaSource)40 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)36 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)30 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)30 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)30 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)30 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)30 TransferListener (androidx.media3.datasource.TransferListener)19 Player (androidx.media3.common.Player)17