Search in sources :

Example 51 with ActionSchedule

use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.

the class ExoPlayerTest method clearMediaItems_correctMasking.

@Test
public void clearMediaItems_correctMasking() throws Exception {
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET };
    final int[] maskingPlaybackState = { C.INDEX_UNSET };
    final long[] currentPosition = { C.TIME_UNSET, C.TIME_UNSET };
    final long[] bufferedPosition = { C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).playUntilPosition(/* mediaItemIndex= */
    1, /* positionMs= */
    150).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            currentPosition[0] = player.getCurrentPosition();
            bufferedPosition[0] = player.getBufferedPosition();
            player.clearMediaItems();
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
            currentPosition[1] = player.getCurrentPosition();
            bufferedPosition[1] = player.getBufferedPosition();
            maskingPlaybackState[0] = player.getPlaybackState();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, /* positionMs= */
    C.TIME_UNSET).setMediaSources(new FakeMediaSource(), new FakeMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
    assertThat(currentPosition[0]).isAtLeast(150);
    assertThat(currentPosition[1]).isEqualTo(0);
    assertThat(bufferedPosition[0]).isAtLeast(150);
    assertThat(bufferedPosition[1]).isEqualTo(0);
    assertArrayEquals(new int[] { 1, 0 }, currentMediaItemIndices);
    assertArrayEquals(new int[] { Player.STATE_ENDED }, maskingPlaybackState);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 52 with ActionSchedule

use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.

the class ExoPlayerTest method testAddMediaSources_skipSettingMediaItems_invalidInitialSeek_correctMaskingMediaItemIndex.

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

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            player.addMediaSource(new FakeMediaSource());
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
        }
    }).prepare().waitForTimelineChanged().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).skipSettingMediaSources().initialSeek(/* mediaItemIndex= */
    1, C.TIME_UNSET).setActionSchedule(actionSchedule).build().start(/* doPrepare= */
    false).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 1, 0, 0 }, currentMediaItemIndices);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 53 with ActionSchedule

use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.

the class ExoPlayerTest method resetPlaylistStartsFromDefaultPosition.

@Test
public void resetPlaylistStartsFromDefaultPosition() throws Exception {
    Object firstWindowId = new Object();
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    firstWindowId));
    Timeline firstExpectedPlaceholderTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(firstWindowId).build());
    Object secondWindowId = new Object();
    Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    secondWindowId));
    Timeline secondExpectedPlaceholderTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(secondWindowId).build());
    MediaSource secondSource = new FakeMediaSource(secondTimeline);
    AtomicLong positionAfterReprepare = new AtomicLong();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    2000).setMediaSources(/* resetPosition= */
    true, secondSource).waitForTimelineChanged(secondTimeline, /* expectedReason */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            positionAfterReprepare.set(player.getCurrentPosition());
        }
    }).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    testRunner.assertTimelinesSame(firstExpectedPlaceholderTimeline, timeline, secondExpectedPlaceholderTimeline, secondTimeline);
    testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
    assertThat(positionAfterReprepare.get()).isEqualTo(0L);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 54 with ActionSchedule

use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.

the class ExoPlayerTest method seekTo_whileReady_callsOnIsPlayingChanged.

@Test
public void seekTo_whileReady_callsOnIsPlayingChanged() throws Exception {
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).seek(/* positionMs= */
    0).waitForPlaybackState(Player.STATE_ENDED).build();
    List<Boolean> onIsPlayingChanges = new ArrayList<>();
    Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onIsPlayingChanged(boolean isPlaying) {
            onIsPlayingChanges.add(isPlaying);
        }
    };
    new ExoPlayerTestRunner.Builder(context).setPlayerListener(playerListener).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(onIsPlayingChanges).containsExactly(true, false, true, false).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) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 55 with ActionSchedule

use of com.google.android.exoplayer2.playbacktests.util.ActionSchedule in project ExoPlayer by google.

the class ExoPlayerTest method setMediaSources_whenEnded_invalidSeek_correctMaskingPlaybackState.

@Test
public void setMediaSources_whenEnded_invalidSeek_correctMaskingPlaybackState() throws Exception {
    final int[] maskingPlaybackStates = new int[1];
    Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Set media item with an invalid implicit seek to the current position.
            player.setMediaSource(new FakeMediaSource(new FakeTimeline(/* windowCount= */
            1, 1L)), /* resetPosition= */
            false);
            maskingPlaybackStates[0] = player.getPlaybackState();
        }
    }).waitForTimelineChanged().waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).initialSeek(/* mediaItemIndex= */
    1, /* positionMs= */
    C.TIME_UNSET).setMediaSources(new ConcatenatingMediaSource()).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    // Expect reset of masking to first media item.
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED);
    assertArrayEquals(new int[] { Player.STATE_ENDED }, maskingPlaybackStates);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)143 Test (org.junit.Test)142 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)103 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)97 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)96 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)84 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)79 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)59 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)59 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)55 MediaSource (com.google.android.exoplayer2.source.MediaSource)40 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)36 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)30 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)30 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)30 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)30 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)30 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)19 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)17 ArrayList (java.util.ArrayList)16