Search in sources :

Example 16 with PlaybackParameters

use of com.google.android.exoplayer2.PlaybackParameters in project ExoPlayer by google.

the class DefaultAudioSinkTest method handlesBufferAfterReset_withPlaybackSpeed.

@Test
public void handlesBufferAfterReset_withPlaybackSpeed() throws Exception {
    defaultAudioSink.setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.5f));
    configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
    defaultAudioSink.handleBuffer(createDefaultSilenceBuffer(), /* presentationTimeUs= */
    0, /* encodedAccessUnitCount= */
    1);
    // After reset and re-configure we can successfully queue more input.
    defaultAudioSink.reset();
    configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
    defaultAudioSink.handleBuffer(createDefaultSilenceBuffer(), /* presentationTimeUs= */
    0, /* encodedAccessUnitCount= */
    1);
    assertThat(defaultAudioSink.getPlaybackParameters()).isEqualTo(new PlaybackParameters(/* speed= */
    1.5f));
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Example 17 with PlaybackParameters

use of com.google.android.exoplayer2.PlaybackParameters in project ExoPlayer by google.

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(com.google.android.exoplayer2.Player.Listener) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) ArrayList(java.util.ArrayList) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 18 with PlaybackParameters

use of com.google.android.exoplayer2.PlaybackParameters in project ExoPlayer by google.

the class MediaPeriodQueueTest method setupTimeline.

private void setupTimeline(Timeline timeline) {
    fakeMediaSource = new FakeMediaSource(timeline);
    MediaSourceList.MediaSourceHolder mediaSourceHolder = new MediaSourceList.MediaSourceHolder(fakeMediaSource, /* useLazyPreparation= */
    false);
    mediaSourceList.setMediaSources(ImmutableList.of(mediaSourceHolder), new FakeShuffleOrder(/* length= */
    1));
    mediaSourceHolder.mediaSource.prepareSource(mock(MediaSourceCaller.class), /* mediaTransferListener */
    null, PlayerId.UNSET);
    Timeline playlistTimeline = mediaSourceList.createTimeline();
    firstPeriodUid = playlistTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    playbackInfo = new PlaybackInfo(playlistTimeline, mediaPeriodQueue.resolveMediaPeriodIdForAds(playlistTimeline, firstPeriodUid, /* positionUs= */
    0), /* requestedContentPositionUs= */
    C.TIME_UNSET, /* discontinuityStartPositionUs= */
    0, Player.STATE_READY, /* playbackError= */
    null, /* isLoading= */
    false, /* trackGroups= */
    null, /* trackSelectorResult= */
    null, /* staticMetadata= */
    ImmutableList.of(), /* loadingMediaPeriodId= */
    null, /* playWhenReady= */
    false, Player.PLAYBACK_SUPPRESSION_REASON_NONE, /* playbackParameters= */
    PlaybackParameters.DEFAULT, /* bufferedPositionUs= */
    0, /* totalBufferedDurationUs= */
    0, /* positionUs= */
    0, /* offloadSchedulingEnabled= */
    false, /* sleepingForOffload= */
    false);
}
Also used : MediaSourceCaller(com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder)

Example 19 with PlaybackParameters

use of com.google.android.exoplayer2.PlaybackParameters in project ExoPlayer by google.

the class ExoPlayerTest method setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked.

@Test
public void setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked() throws Exception {
    List<Float> maskedPlaybackSpeeds = new ArrayList<>();
    Action getPlaybackSpeedAction = new Action("getPlaybackSpeed", /* description= */
    null) {

        @Override
        protected void doActionImpl(ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
            maskedPlaybackSpeeds.add(player.getPlaybackParameters().speed);
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.1f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.2f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
    1.3f)).apply(getPlaybackSpeedAction).play().build();
    List<Float> reportedPlaybackSpeeds = new ArrayList<>();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            reportedPlaybackSpeeds.add(playbackParameters.speed);
        }
    };
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(reportedPlaybackSpeeds).containsExactly(1.1f, 1.2f, 1.3f).inOrder();
    assertThat(maskedPlaybackSpeeds).isEqualTo(reportedPlaybackSpeeds);
}
Also used : Action(com.google.android.exoplayer2.testutil.Action) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) Surface(android.view.Surface) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) Listener(com.google.android.exoplayer2.Player.Listener) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 20 with PlaybackParameters

use of com.google.android.exoplayer2.PlaybackParameters in project ExoPlayer by google.

the class PlaybackStatsListenerTest method events_duringInitialIdleState_dontCreateNewPlaybackStats.

@Test
public void events_duringInitialIdleState_dontCreateNewPlaybackStats() throws Exception {
    PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
    true, /* callback= */
    null);
    player.addAnalyticsListener(playbackStatsListener);
    player.seekTo(/* positionMs= */
    1234);
    runUntilPendingCommandsAreFullyHandled(player);
    player.setPlaybackParameters(new PlaybackParameters(/* speed= */
    2f));
    runUntilPendingCommandsAreFullyHandled(player);
    player.play();
    runUntilPendingCommandsAreFullyHandled(player);
    assertThat(playbackStatsListener.getPlaybackStats()).isNull();
}
Also used : PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) Test(org.junit.Test)

Aggregations

PlaybackParameters (com.google.android.exoplayer2.PlaybackParameters)20 Test (org.junit.Test)17 Listener (com.google.android.exoplayer2.Player.Listener)7 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)7 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)7 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 ArrayList (java.util.ArrayList)4 Nullable (androidx.annotation.Nullable)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)3 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)3 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)3 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)3 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)3 FakeMediaClockRenderer (com.google.android.exoplayer2.testutil.FakeMediaClockRenderer)3 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)3 Surface (android.view.Surface)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)2