Search in sources :

Example 31 with PlaybackParameters

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

the class ExoPlayerTest method targetLiveOffsetInMedia_withSetPlaybackParameters_usesPlaybackParameterSpeed.

@Test
public void targetLiveOffsetInMedia_withSetPlaybackParameters_usesPlaybackParameterSpeed() throws Exception {
    long windowStartUnixTimeMs = 987_654_321_000L;
    long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
    ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
    nowUnixTimeMs, /* isAutoAdvancing= */
    true)).build();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    true, /* isLive= */
    true, /* isPlaceholder= */
    false, /* durationUs= */
    1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    20 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
    Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.pause();
    player.setMediaSource(new FakeMediaSource(timeline));
    player.prepare();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
    long liveOffsetAtStart = player.getCurrentLiveOffset();
    // Verify test setup (now = 20 seconds in live window, default start position = 20 seconds).
    assertThat(liveOffsetAtStart).isIn(Range.closed(-100L, 100L));
    player.setPlaybackParameters(new PlaybackParameters(/* speed */
    2.0f));
    // Play until close to the end of the available live window.
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    999_000);
    long liveOffsetAtEnd = player.getCurrentLiveOffset();
    player.release();
    // Assert that the player didn't adjust the live offset to the media value (9 seconds) and
    // instead played the media with double speed (resulting in a negative live offset).
    assertThat(liveOffsetAtEnd).isLessThan(0);
    // Assert that user-set speed was reported
    verify(mockListener).onPlaybackParametersChanged(new PlaybackParameters(2.0f));
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) 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