Search in sources :

Example 36 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method removeMediaItem_removePlayingWindow_correctMaskingPosition.

@Test
public void removeMediaItem_removePlayingWindow_correctMaskingPosition() throws Exception {
    final int[] mediaItemIndex = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] positionMs = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] bufferedPositions = { C.INDEX_UNSET, C.INDEX_UNSET };
    final long[] totalBufferedDuration = { C.INDEX_UNSET, C.INDEX_UNSET };
    runPositionMaskingCapturingActionSchedule(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.removeMediaItem(/* index= */
            0);
        }
    }, /* pauseMediaItemIndex= */
    0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
    4000));
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(positionMs[0]).isEqualTo(0);
    // TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully
    // covered.
    // assertThat(bufferedPositions[0]).isEqualTo(4000);
    // assertThat(totalBufferedDuration[0]).isEqualTo(4000);
    assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
    assertThat(positionMs[1]).isEqualTo(positionMs[0]);
    assertThat(bufferedPositions[1]).isEqualTo(4000);
    assertThat(totalBufferedDuration[1]).isEqualTo(4000);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Test(org.junit.Test)

Example 37 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method moveMediaItems_correctMaskingMediaItemIndex.

@Test
public void moveMediaItems_correctMaskingMediaItemIndex() throws Exception {
    Timeline timeline = new FakeTimeline();
    MediaSource firstMediaSource = new FakeMediaSource(timeline);
    MediaSource secondMediaSource = new FakeMediaSource(timeline);
    MediaSource thirdMediaSource = new FakeMediaSource(timeline);
    final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move the current item down in the playlist.
            player.moveMediaItems(/* fromIndex= */
            0, /* toIndex= */
            2, /* newIndex= */
            1);
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
        }
    }).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move the current item up in the playlist.
            player.moveMediaItems(/* fromIndex= */
            1, /* toIndex= */
            3, /* newIndex= */
            0);
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
        }
    }).seek(/* mediaItemIndex= */
    2, C.TIME_UNSET).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move items from before to behind the current item.
            player.moveMediaItems(/* fromIndex= */
            0, /* toIndex= */
            2, /* newIndex= */
            1);
            currentMediaItemIndices[2] = player.getCurrentMediaItemIndex();
        }
    }).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move items from behind to before the current item.
            player.moveMediaItems(/* fromIndex= */
            1, /* toIndex= */
            3, /* newIndex= */
            0);
            currentMediaItemIndices[3] = player.getCurrentMediaItemIndex();
        }
    }).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move items from before to before the current item.
            // No change in currentMediaItemIndex.
            player.moveMediaItems(/* fromIndex= */
            0, /* toIndex= */
            1, /* newIndex= */
            1);
            currentMediaItemIndices[4] = player.getCurrentMediaItemIndex();
        }
    }).seek(/* mediaItemIndex= */
    0, C.TIME_UNSET).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            // Move items from behind to behind the current item.
            // No change in currentMediaItemIndex.
            player.moveMediaItems(/* fromIndex= */
            1, /* toIndex= */
            2, /* newIndex= */
            2);
            currentMediaItemIndices[5] = player.getCurrentMediaItemIndex();
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(firstMediaSource, secondMediaSource, thirdMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertArrayEquals(new int[] { 1, 0, 0, 2, 2, 0 }, currentMediaItemIndices);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) 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) 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) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 38 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method removeMediaItems_correctMaskingMediaItemIndex.

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

        @Override
        public void run(ExoPlayer player) {
            // Decrease current media item index.
            currentMediaItemIndices[0] = player.getCurrentMediaItemIndex();
            player.removeMediaItem(/* index= */
            0);
            currentMediaItemIndices[1] = player.getCurrentMediaItemIndex();
        }
    }).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);
}
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 39 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method recursiveTimelineChangeInStopAreReportedInCorrectOrder.

@Test
public void recursiveTimelineChangeInStopAreReportedInCorrectOrder() throws Exception {
    Timeline firstTimeline = new FakeTimeline(/* windowCount= */
    2);
    Timeline secondTimeline = new FakeTimeline(/* windowCount= */
    3);
    final AtomicReference<ExoPlayer> playerReference = new AtomicReference<>();
    FakeMediaSource secondMediaSource = new FakeMediaSource(secondTimeline);
    final Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onPlaybackStateChanged(int playbackState) {
            if (playbackState == Player.STATE_IDLE) {
                playerReference.get().setMediaSource(secondMediaSource);
            }
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            playerReference.set(player);
            player.addListener(playerListener);
        }
    }).delay(1).stop(/* reset= */
    true).waitForPlaybackState(Player.STATE_IDLE).prepare().waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setTimeline(firstTimeline).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    exoPlayerTestRunner.assertTimelinesSame(new FakeMediaSource.InitialTimeline(firstTimeline), firstTimeline, Timeline.EMPTY, new FakeMediaSource.InitialTimeline(secondTimeline), secondTimeline);
    exoPlayerTestRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
Also used : 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) 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) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 40 with PlayerRunnable

use of com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable in project ExoPlayer by google.

the class ExoPlayerTest method contentWithoutInitialSeekStartsAtDefaultPositionAfterPrerollAd.

@Test
public void contentWithoutInitialSeekStartsAtDefaultPositionAfterPrerollAd() throws Exception {
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    3, /* adGroupTimesUs...= */
    0);
    Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10_000_000, /* defaultPositionUs= */
    5_000_000, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, adPlaybackState));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(/* timeline= */
    null);
    AtomicReference<Player> playerReference = new AtomicReference<>();
    AtomicLong contentStartPositionMs = new AtomicLong(C.TIME_UNSET);
    Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
            if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
                contentStartPositionMs.set(playerReference.get().getContentPosition());
            }
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            playerReference.set(player);
            player.addListener(playerListener);
        }
    }).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(() -> fakeMediaSource.setNewSourceInfo(fakeTimeline)).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(fakeMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(contentStartPositionMs.get()).isAtLeast(5_000L);
}
Also used : 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) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DiscontinuityReason(com.google.android.exoplayer2.Player.DiscontinuityReason) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) AtomicLong(java.util.concurrent.atomic.AtomicLong) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) 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)

Aggregations

PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)93 Test (org.junit.Test)91 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)76 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)74 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)56 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)51 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)43 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)34 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)28 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)28 MediaSource (com.google.android.exoplayer2.source.MediaSource)21 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)20 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)20 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)20 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)20 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)20 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)18 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11