Search in sources :

Example 71 with TimelineWindowDefinition

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

the class ExoPlayerTest method isCommandAvailable_duringAd_isFalseForSeekCommands.

@Test
public void isCommandAvailable_duringAd_isFalseForSeekCommands() throws Exception {
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdUri(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, Uri.EMPTY).withAdDurationsUs(/* adDurationUs= */
    new long[][] { { Util.msToUs(4_000) } });
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10_000), adPlaybackState));
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(adTimeline), new FakeMediaSource()));
    player.seekTo(/* mediaItemIndex= */
    1, /* positionMs= */
    0);
    player.prepare();
    runUntilPlaybackState(player, Player.STATE_READY);
    assertThat(player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_BACK)).isFalse();
    assertThat(player.isCommandAvailable(COMMAND_SEEK_FORWARD)).isFalse();
}
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) 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) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 72 with TimelineWindowDefinition

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

the class DefaultAnalyticsCollectorTest method seekAfterMidroll.

@Test
public void seekAfterMidroll() throws Exception {
    long windowOffsetInFirstPeriodUs = TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    Timeline adTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND)));
    FakeMediaSource fakeMediaSource = new FakeMediaSource(adTimeline, DrmSessionManager.DRM_UNSUPPORTED, (unusedFormat, mediaPeriodId) -> {
        if (mediaPeriodId.isAd()) {
            return ImmutableList.of(oneByteSample(/* timeUs= */
            0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        } else {
            // Provide a sample before the midroll and another after the seek point below (6s).
            return ImmutableList.of(oneByteSample(windowOffsetInFirstPeriodUs + C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), oneByteSample(windowOffsetInFirstPeriodUs + 7 * C.MICROS_PER_SECOND, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM);
        }
    }, ExoPlayerTestRunner.VIDEO_FORMAT);
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForIsLoading(true).waitForIsLoading(false).seek(6 * C.MICROS_PER_SECOND).waitForIsLoading(true).play().waitForPlaybackState(Player.STATE_ENDED).build();
    TestAnalyticsListener listener = runAnalyticsTest(fakeMediaSource, actionSchedule);
    Object periodUid = listener.lastReportedTimeline.getUidOfPeriod(/* periodIndex= */
    0);
    EventWindowAndPeriodId midrollAd = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0));
    EventWindowAndPeriodId contentBeforeMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    0));
    EventWindowAndPeriodId contentAfterMidroll = new EventWindowAndPeriodId(/* windowIndex= */
    0, new MediaPeriodId(periodUid, /* windowSequenceNumber= */
    0, /* nextAdGroupIndex= */
    C.INDEX_UNSET));
    assertThat(listener.getEvents(EVENT_PLAYER_STATE_CHANGED)).containsExactly(WINDOW_0, /* setPlayWhenReady=true */
    WINDOW_0, /* setPlayWhenReady=false */
    WINDOW_0, /* BUFFERING */
    contentBeforeMidroll, /* READY */
    contentAfterMidroll, /* BUFFERING */
    midrollAd, /* setPlayWhenReady=true */
    midrollAd, /* READY */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)).containsExactly(WINDOW_0, /* PLAYLIST_CHANGED */
    contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_POSITION_DISCONTINUITY)).containsExactly(contentAfterMidroll, /* seek */
    midrollAd, /* seek adjustment */
    contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_IS_LOADING_CHANGED)).containsExactly(contentBeforeMidroll, contentBeforeMidroll, midrollAd, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_LOAD_STARTED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_LOAD_COMPLETED)).containsExactly(WINDOW_0, /* content manifest */
    contentBeforeMidroll, midrollAd, contentAfterMidroll, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DOWNSTREAM_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_INIT)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_ENABLED)).containsExactly(contentBeforeMidroll, midrollAd).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(contentBeforeMidroll);
    assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterMidroll);
    assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll).inOrder();
    assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(contentAfterMidroll);
    listener.assertNoMoreEvents();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) 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) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 73 with TimelineWindowDefinition

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

the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_behindAdPositionInSinglePeriodTimeline_resolvesToAd.

@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_behindAdPositionInSinglePeriodTimeline_resolvesToAd() {
    long adPositionUs = DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 10_000;
    AdPlaybackState adPlaybackState = new AdPlaybackState("adsId", adPositionUs);
    adPlaybackState = adPlaybackState.withAdDurationsUs(/* adGroupIndex= */
    0, 5_000);
    Object windowUid = new Object();
    FakeTimeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    windowUid, /* isSeekable= */
    true, /* isDynamic= */
    false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, adPlaybackState));
    MediaPeriodId mediaPeriodId = mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, /* periodUid= */
    new Pair<>(windowUid, 0), adPositionUs + 1);
    assertThat(mediaPeriodId.adGroupIndex).isEqualTo(0);
    assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(0);
    assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(-1);
    assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 74 with TimelineWindowDefinition

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

the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_beforeAdPositionInSinglePeriodTimeline_seekNotAdjusted.

@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_beforeAdPositionInSinglePeriodTimeline_seekNotAdjusted() {
    long adPositionUs = DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 10_000;
    AdPlaybackState adPlaybackState = new AdPlaybackState("adsId", adPositionUs).withAdDurationsUs(/* adGroupIndex= */
    0, 5_000);
    Object windowUid = new Object();
    FakeTimeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    windowUid, /* isSeekable= */
    true, /* isDynamic= */
    false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, adPlaybackState));
    MediaPeriodId mediaPeriodId = mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, new Pair<>(windowUid, 0), adPositionUs - 1);
    assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
    assertThat(mediaPeriodId.adGroupIndex).isEqualTo(-1);
    assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(-1);
    assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(0);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 75 with TimelineWindowDefinition

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

the class MediaPeriodQueueTest method resolveMediaPeriodIdForAdsAfterPeriodPositionChange_toAdPositionInSinglePeriodTimeline_resolvesToAd.

@Test
public void resolveMediaPeriodIdForAdsAfterPeriodPositionChange_toAdPositionInSinglePeriodTimeline_resolvesToAd() {
    long adPositionUs = DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 10_000;
    AdPlaybackState adPlaybackState = new AdPlaybackState("adsId", adPositionUs);
    adPlaybackState = adPlaybackState.withAdDurationsUs(/* adGroupIndex= */
    0, 5_000);
    Object windowUid = new Object();
    FakeTimeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    windowUid, /* isSeekable= */
    true, /* isDynamic= */
    false, TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US, adPlaybackState));
    MediaPeriodId mediaPeriodId = mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, /* periodUid= */
    new Pair<>(windowUid, 0), adPositionUs);
    assertThat(mediaPeriodId.periodUid).isEqualTo(new Pair<>(windowUid, 0));
    assertThat(mediaPeriodId.adGroupIndex).isEqualTo(0);
    assertThat(mediaPeriodId.adIndexInAdGroup).isEqualTo(0);
    assertThat(mediaPeriodId.nextAdGroupIndex).isEqualTo(-1);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)103 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)101 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)101 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)79 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)69 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)61 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)61 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)35 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)30 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)28 Listener (com.google.android.exoplayer2.Player.Listener)27 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)26 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)22 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)20 Timeline (com.google.android.exoplayer2.Timeline)19 MediaSource (com.google.android.exoplayer2.source.MediaSource)19 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)18 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)16 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)16 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)16