Search in sources :

Example 56 with ActionSchedule

use of com.google.android.exoplayer2.testutil.ActionSchedule 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 57 with ActionSchedule

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

the class ExoPlayerTest method sendMessagesMoveCurrentMediaItemIndex.

@Test
public void sendMessagesMoveCurrentMediaItemIndex() throws Exception {
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0));
    final Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1), new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0));
    final FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForTimelineChanged(timeline, /* expectedReason */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).sendMessage(target, /* positionMs= */
    50).executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline)).waitForTimelineChanged(secondTimeline, /* expectedReason */
    Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(target.positionMs).isAtLeast(50L);
    assertThat(target.mediaItemIndex).isEqualTo(1);
}
Also used : NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) 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 58 with ActionSchedule

use of com.google.android.exoplayer2.testutil.ActionSchedule 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 59 with ActionSchedule

use of com.google.android.exoplayer2.testutil.ActionSchedule 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 60 with ActionSchedule

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

the class ExoPlayerTest method sendMessagesAtStartAndEndOfPeriod.

@Test
public void sendMessagesAtStartAndEndOfPeriod() throws Exception {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    PositionGrabbingMessageTarget targetStartFirstPeriod = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget targetEndMiddlePeriodResolved = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget targetEndMiddlePeriodUnresolved = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget targetStartMiddlePeriod = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget targetEndLastPeriodResolved = new PositionGrabbingMessageTarget();
    PositionGrabbingMessageTarget targetEndLastPeriodUnresolved = new PositionGrabbingMessageTarget();
    long duration1Ms = timeline.getWindow(0, new Window()).getDurationMs();
    long duration2Ms = timeline.getWindow(1, new Window()).getDurationMs();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).sendMessage(targetStartFirstPeriod, /* mediaItemIndex= */
    0, /* positionMs= */
    0).sendMessage(targetEndMiddlePeriodResolved, /* mediaItemIndex= */
    0, /* positionMs= */
    duration1Ms - 1).sendMessage(targetEndMiddlePeriodUnresolved, /* mediaItemIndex= */
    0, /* positionMs= */
    C.TIME_END_OF_SOURCE).sendMessage(targetStartMiddlePeriod, /* mediaItemIndex= */
    1, /* positionMs= */
    0).sendMessage(targetEndLastPeriodResolved, /* mediaItemIndex= */
    1, /* positionMs= */
    duration2Ms - 1).sendMessage(targetEndLastPeriodUnresolved, /* mediaItemIndex= */
    1, /* positionMs= */
    C.TIME_END_OF_SOURCE).waitForMessage(targetEndLastPeriodUnresolved).build();
    new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(targetStartFirstPeriod.mediaItemIndex).isEqualTo(0);
    assertThat(targetStartFirstPeriod.positionMs).isAtLeast(0L);
    assertThat(targetEndMiddlePeriodResolved.mediaItemIndex).isEqualTo(0);
    assertThat(targetEndMiddlePeriodResolved.positionMs).isAtLeast(duration1Ms - 1);
    assertThat(targetEndMiddlePeriodUnresolved.mediaItemIndex).isEqualTo(0);
    assertThat(targetEndMiddlePeriodUnresolved.positionMs).isAtLeast(duration1Ms - 1);
    assertThat(targetEndMiddlePeriodResolved.positionMs).isEqualTo(targetEndMiddlePeriodUnresolved.positionMs);
    assertThat(targetStartMiddlePeriod.mediaItemIndex).isEqualTo(1);
    assertThat(targetStartMiddlePeriod.positionMs).isAtLeast(0L);
    assertThat(targetEndLastPeriodResolved.mediaItemIndex).isEqualTo(1);
    assertThat(targetEndLastPeriodResolved.positionMs).isAtLeast(duration2Ms - 1);
    assertThat(targetEndLastPeriodUnresolved.mediaItemIndex).isEqualTo(1);
    assertThat(targetEndLastPeriodUnresolved.positionMs).isAtLeast(duration2Ms - 1);
    assertThat(targetEndLastPeriodResolved.positionMs).isEqualTo(targetEndLastPeriodUnresolved.positionMs);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) 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