Search in sources :

Example 1 with FakeMediaClockRenderer

use of androidx.media3.test.utils.FakeMediaClockRenderer 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 FakeMediaClockRenderer

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

the class ExoPlayerTest method setPlaybackSpeed_withAdPlayback_onlyAppliesToContent.

@Test
public void setPlaybackSpeed_withAdPlayback_onlyAppliesToContent() throws Exception {
    // Create renderer with media clock to listen to playback parameter changes.
    ArrayList<PlaybackParameters> playbackParameters = new ArrayList<>();
    FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {

        private long positionUs;

        @Override
        protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) {
            this.positionUs = offsetUs;
        }

        @Override
        public long getPositionUs() {
            // Continuously increase position to let playback progress.
            positionUs += 10_000;
            return positionUs;
        }

        @Override
        public void setPlaybackParameters(PlaybackParameters parameters) {
            playbackParameters.add(parameters);
        }

        @Override
        public PlaybackParameters getPlaybackParameters() {
            return playbackParameters.isEmpty() ? PlaybackParameters.DEFAULT : Iterables.getLast(playbackParameters);
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(audioRenderer).build();
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    0, 7 * C.MICROS_PER_SECOND, C.TIME_END_OF_SOURCE);
    TimelineWindowDefinition adTimelineDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, /* windowOffsetInFirstPeriodUs= */
    0, adPlaybackState);
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimelineDefinition), ExoPlayerTestRunner.AUDIO_FORMAT));
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setPlaybackSpeed(5f);
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // Assert that the renderer received the playback speed updates at each ad/content boundary.
    assertThat(playbackParameters).containsExactly(/* preroll ad */
    new PlaybackParameters(1f), /* content after preroll */
    new PlaybackParameters(5f), /* midroll ad */
    new PlaybackParameters(1f), /* content after midroll */
    new PlaybackParameters(5f), /* postroll ad */
    new PlaybackParameters(1f), /* content after postroll */
    new PlaybackParameters(5f)).inOrder();
    // Assert that user-set speed was reported, but none of the ad overrides.
    verify(mockListener).onPlaybackParametersChanged(any());
    verify(mockListener).onPlaybackParametersChanged(new PlaybackParameters(5.0f));
}
Also used : Listener(androidx.media3.common.Player.Listener) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) AdPlaybackState(androidx.media3.common.AdPlaybackState) FakeTimeline(androidx.media3.test.utils.FakeTimeline) ArrayList(java.util.ArrayList) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) PlaybackParameters(androidx.media3.common.PlaybackParameters) Test(org.junit.Test)

Example 3 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method enableRendererMediaClockWithFixedButSamePlaybackSpeed_shouldNotTriggerCallback.

@Test
public void enableRendererMediaClockWithFixedButSamePlaybackSpeed_shouldNotTriggerCallback() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(PlaybackParameters.DEFAULT, /* playbackParametersAreMutable= */
    false);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    verifyNoMoreInteractions(listener);
}
Also used : FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) Test(org.junit.Test)

Example 4 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method disableRendererMediaClock_shouldKeepPlaybackSpeed.

@Test
public void disableRendererMediaClock_shouldKeepPlaybackSpeed() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(TEST_PLAYBACK_PARAMETERS, /* playbackParametersAreMutable= */
    false);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    mediaClock.onRendererDisabled(mediaClockRenderer);
    mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false);
    assertThat(mediaClock.getPlaybackParameters()).isEqualTo(TEST_PLAYBACK_PARAMETERS);
}
Also used : FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) Test(org.junit.Test)

Example 5 with FakeMediaClockRenderer

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

the class DefaultMediaClockTest method enableRendererMediaClockWithFixedPlaybackSpeed_usesRendererPlaybackSpeed.

@Test
public void enableRendererMediaClockWithFixedPlaybackSpeed_usesRendererPlaybackSpeed() throws ExoPlaybackException {
    FakeMediaClockRenderer mediaClockRenderer = new MediaClockRenderer(TEST_PLAYBACK_PARAMETERS, /* playbackParametersAreMutable= */
    false);
    mediaClock.onRendererEnabled(mediaClockRenderer);
    assertThat(mediaClock.getPlaybackParameters()).isEqualTo(TEST_PLAYBACK_PARAMETERS);
}
Also used : FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) FakeMediaClockRenderer(androidx.media3.test.utils.FakeMediaClockRenderer) Test(org.junit.Test)

Aggregations

FakeMediaClockRenderer (androidx.media3.test.utils.FakeMediaClockRenderer)11 Test (org.junit.Test)11 PlaybackParameters (androidx.media3.common.PlaybackParameters)3 Player (androidx.media3.common.Player)3 Listener (androidx.media3.common.Player.Listener)3 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)2 FakeRenderer (androidx.media3.test.utils.FakeRenderer)2 FakeTimeline (androidx.media3.test.utils.FakeTimeline)2 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)2 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)2 ArrayList (java.util.ArrayList)2 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 Timeline (androidx.media3.common.Timeline)1 TransferListener (androidx.media3.datasource.TransferListener)1 AnalyticsListener (androidx.media3.exoplayer.analytics.AnalyticsListener)1 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)1 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)1 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)1 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)1 ActionSchedule (androidx.media3.test.utils.ActionSchedule)1