Search in sources :

Example 11 with ActionSchedule

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

the class ExoPlayerTest method emptyMultiWindowMediaSource_doesNotEnterBufferState.

@Test
public void emptyMultiWindowMediaSource_doesNotEnterBufferState() throws Exception {
    ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */
    false);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatingMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED);
}
Also used : ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 12 with ActionSchedule

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

the class ExoPlayerTest method seekTo_whilePlayingAd_correctMasking.

@Test
public void seekTo_whilePlayingAd_correctMasking() throws Exception {
    long contentDurationMs = 10_000;
    long adDurationMs = 4_000;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0);
    adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1);
    adPlaybackState = adPlaybackState.withAdUri(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, Uri.EMPTY);
    long[][] durationsUs = new long[1][];
    durationsUs[0] = new long[] { Util.msToUs(adDurationMs) };
    adPlaybackState = adPlaybackState.withAdDurationsUs(durationsUs);
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(contentDurationMs), adPlaybackState));
    FakeMediaSource adsMediaSource = new FakeMediaSource(adTimeline);
    int[] mediaItemIndex = new int[] { C.INDEX_UNSET, C.INDEX_UNSET };
    long[] positionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
    long[] bufferedPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
    long[] totalBufferedDurationMs = new long[] { C.TIME_UNSET, C.TIME_UNSET };
    boolean[] isPlayingAd = new boolean[2];
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).waitForIsLoading(true).waitForIsLoading(false).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.seekTo(/* mediaItemIndex= */
            0, /* positionMs= */
            8000);
            mediaItemIndex[0] = player.getCurrentMediaItemIndex();
            isPlayingAd[0] = player.isPlayingAd();
            positionMs[0] = player.getCurrentPosition();
            bufferedPositionMs[0] = player.getBufferedPosition();
            totalBufferedDurationMs[0] = player.getTotalBufferedDuration();
        }
    }).waitForPendingPlayerCommands().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            mediaItemIndex[1] = player.getCurrentMediaItemIndex();
            isPlayingAd[1] = player.isPlayingAd();
            positionMs[1] = player.getCurrentPosition();
            bufferedPositionMs[1] = player.getBufferedPosition();
            totalBufferedDurationMs[1] = player.getTotalBufferedDuration();
        }
    }).stop().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(adsMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(mediaItemIndex[0]).isEqualTo(0);
    assertThat(isPlayingAd[0]).isTrue();
    assertThat(positionMs[0]).isEqualTo(0);
    assertThat(bufferedPositionMs[0]).isEqualTo(adDurationMs);
    assertThat(totalBufferedDurationMs[0]).isEqualTo(adDurationMs);
    assertThat(mediaItemIndex[1]).isEqualTo(0);
    assertThat(isPlayingAd[1]).isTrue();
    assertThat(positionMs[1]).isEqualTo(0);
    assertThat(bufferedPositionMs[1]).isEqualTo(adDurationMs);
    assertThat(totalBufferedDurationMs[1]).isEqualTo(adDurationMs);
}
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) 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) Test(org.junit.Test)

Example 13 with ActionSchedule

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

the class ExoPlayerTest method mediaItemOfSources_correctInTimelineWindows.

@Test
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
    TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    1, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake1"));
    FakeMediaSource fakeMediaSource1 = new FakeMediaSource(new FakeTimeline(window1));
    TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    2, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake2"));
    FakeMediaSource fakeMediaSource2 = new FakeMediaSource(new FakeTimeline(window2));
    TimelineWindowDefinition window3 = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    3, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs = */
    100_000, /* defaultPositionUs = */
    0, /* windowOffsetInFirstPeriodUs= */
    0, ImmutableList.of(AdPlaybackState.NONE), MediaItem.fromUri("http://foo.bar/fake3"));
    FakeMediaSource fakeMediaSource3 = new FakeMediaSource(new FakeTimeline(window3));
    final Player[] playerHolder = { null };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            playerHolder[0] = player;
        }
    }).waitForPlaybackState(Player.STATE_READY).seek(/* positionMs= */
    0).play().build();
    List<MediaItem> currentMediaItems = new ArrayList<>();
    List<MediaItem> mediaItemsInTimeline = new ArrayList<>();
    Player.Listener playerListener = new Player.Listener() {

        @Override
        public void onTimelineChanged(Timeline timeline, int reason) {
            if (reason != Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
                return;
            }
            Window window = new Window();
            for (int i = 0; i < timeline.getWindowCount(); i++) {
                mediaItemsInTimeline.add(timeline.getWindow(i, window).mediaItem);
            }
        }

        @Override
        public void onPositionDiscontinuity(int reason) {
            if (reason == Player.DISCONTINUITY_REASON_SEEK || reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
                currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
            }
        }
    };
    new ExoPlayerTestRunner.Builder(context).setPlayerListener(playerListener).setActionSchedule(actionSchedule).setMediaSources(fakeMediaSource1, fakeMediaSource2, fakeMediaSource3).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    assertThat(currentMediaItems.get(0).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake1");
    assertThat(currentMediaItems.get(1).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake2");
    assertThat(currentMediaItems.get(2).localConfiguration.uri.toString()).isEqualTo("http://foo.bar/fake3");
    assertThat(mediaItemsInTimeline).containsExactlyElementsIn(currentMediaItems);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) 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) ArrayList(java.util.ArrayList) 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) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 14 with ActionSchedule

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

the class ExoPlayerTest method setShuffleMode_correctPositionMasking.

@Test
public void setShuffleMode_correctPositionMasking() throws Exception {
    long[] currentPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    long[] bufferedPositionMs = new long[] { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).playUntilPosition(0, 5000).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            currentPositionMs[0] = player.getCurrentPosition();
            bufferedPositionMs[0] = player.getBufferedPosition();
            player.setShuffleModeEnabled(true);
            currentPositionMs[1] = player.getCurrentPosition();
            bufferedPositionMs[1] = player.getBufferedPosition();
            player.setShuffleModeEnabled(false);
            currentPositionMs[2] = player.getCurrentPosition();
            bufferedPositionMs[2] = player.getBufferedPosition();
        }
    }).play().build();
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    assertThat(currentPositionMs[0]).isAtLeast(5000);
    assertThat(currentPositionMs[1]).isEqualTo(currentPositionMs[0]);
    assertThat(currentPositionMs[2]).isEqualTo(currentPositionMs[0]);
    assertThat(bufferedPositionMs[0]).isGreaterThan(currentPositionMs[0]);
    assertThat(bufferedPositionMs[1]).isEqualTo(bufferedPositionMs[0]);
    assertThat(bufferedPositionMs[2]).isEqualTo(bufferedPositionMs[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) Test(org.junit.Test)

Example 15 with ActionSchedule

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

the class ExoPlayerTest method setMediaSources_whenEnded_noSeek_correctMaskingPlaybackState.

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

        @Override
        public void run(ExoPlayer player) {
            // Set media item with no seek (keep current position).
            player.setMediaSource(new FakeMediaSource(), /* resetPosition= */
            false);
            maskingPlaybackStates[0] = player.getPlaybackState();
        }
    }).waitForTimelineChanged().waitForPlaybackState(Player.STATE_ENDED).build();
    ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
    // Expect reset of masking to first media item.
    exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED);
    assertArrayEquals(new int[] { Player.STATE_ENDED }, maskingPlaybackStates);
    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 : 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)

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