Search in sources :

Example 11 with PlayerRunnable

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

the class ExoPlayerTest method cancelMessageBeforeDelivery.

@Test
public void cancelMessageBeforeDelivery() throws Exception {
    final PositionGrabbingMessageTarget target = new PositionGrabbingMessageTarget();
    final AtomicReference<PlayerMessage> message = new AtomicReference<>();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            message.set(player.createMessage(target).setPosition(/* positionMs= */
            50).send());
        }
    }).playUntilPosition(/* mediaItemIndex= */
    0, /* positionMs= */
    30).executeRunnable(() -> message.get().cancel()).play().build();
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(message.get().isCanceled()).isTrue();
    assertThat(target.messageCount).isEqualTo(0);
}
Also used : 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) Test(org.junit.Test)

Example 12 with PlayerRunnable

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

the class ExoPlayerTest method moveMediaItem_behindLoadingPeriod_correctMaskingPosition.

@Test
public void moveMediaItem_behindLoadingPeriod_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.moveMediaItem(/* currentIndex= */
            1, /* newIndex= */
            2);
        }
    }, /* pauseMediaItemIndex= */
    0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
    4000));
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(positionMs[0]).isAtLeast(8000);
    assertThat(bufferedPositions[0]).isEqualTo(10_000);
    assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]);
    assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
    assertThat(positionMs[1]).isEqualTo(positionMs[0]);
    assertThat(bufferedPositions[1]).isEqualTo(10_000);
    assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Test(org.junit.Test)

Example 13 with PlayerRunnable

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

the class ExoPlayerTest method clearMediaItems_correctMaskingPosition.

@Test
public void clearMediaItems_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.clearMediaItems();
        }
    }, /* pauseMediaItemIndex= */
    0, mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */
    4000));
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(positionMs[0]).isEqualTo(0);
    assertThat(bufferedPositions[0]).isEqualTo(0);
    assertThat(totalBufferedDuration[0]).isEqualTo(0);
    assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]);
    assertThat(positionMs[1]).isEqualTo(positionMs[0]);
    assertThat(bufferedPositions[1]).isEqualTo(bufferedPositions[0]);
    assertThat(totalBufferedDuration[1]).isEqualTo(totalBufferedDuration[0]);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Test(org.junit.Test)

Example 14 with PlayerRunnable

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

the class ExoPlayerTest method multipleListenersAndMultipleCallbacks_callbacksAreOrderedByType.

@Test
public void multipleListenersAndMultipleCallbacks_callbacksAreOrderedByType() throws Exception {
    String playWhenReadyChange1 = "playWhenReadyChange1";
    String playWhenReadyChange2 = "playWhenReadyChange2";
    String isPlayingChange1 = "isPlayingChange1";
    String isPlayingChange2 = "isPlayingChange2";
    ArrayList<String> events = new ArrayList<>();
    Player.Listener playerListener1 = new Player.Listener() {

        @Override
        public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
            events.add(playWhenReadyChange1);
        }

        @Override
        public void onIsPlayingChanged(boolean isPlaying) {
            events.add(isPlayingChange1);
        }
    };
    Player.Listener playerListener2 = new Player.Listener() {

        @Override
        public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
            events.add(playWhenReadyChange2);
        }

        @Override
        public void onIsPlayingChanged(boolean isPlaying) {
            events.add(isPlayingChange2);
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.addListener(playerListener1);
            player.addListener(playerListener2);
        }
    }).waitForPlaybackState(Player.STATE_READY).play().waitForPlaybackState(Player.STATE_ENDED).build();
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(events).containsExactly(playWhenReadyChange1, playWhenReadyChange2, isPlayingChange1, isPlayingChange2, isPlayingChange1, isPlayingChange2).inOrder();
}
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) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) Listener(com.google.android.exoplayer2.Player.Listener) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 15 with PlayerRunnable

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

the class ExoPlayerTest method seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback.

@Test
public void seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback() throws Exception {
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount = */
    1));
    AtomicInteger mediaItemIndexAfterFinalEndedState = new AtomicInteger();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).addMediaSources(mediaSource).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.seekTo(player.getCurrentPosition());
        }
    }).waitForPlaybackState(Player.STATE_READY).waitForPlaybackState(Player.STATE_ENDED).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndexAfterFinalEndedState.set(player.getCurrentMediaItemIndex());
        }
    }).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(mediaItemIndexAfterFinalEndedState.get()).isEqualTo(1);
}
Also used : 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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)

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