Search in sources :

Example 1 with SinglePeriodAdTimeline

use of com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline in project ExoPlayer by google.

the class AdsMediaSourceTest method createPeriod_preparesChildAdMediaSourceAndRefreshesSourceInfo.

@Test
public void createPeriod_preparesChildAdMediaSourceAndRefreshesSourceInfo() {
    contentMediaSource.setNewSourceInfo(CONTENT_TIMELINE);
    adsMediaSource.createPeriod(new MediaPeriodId(CONTENT_PERIOD_UID, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0), mock(Allocator.class), /* startPositionUs= */
    0);
    shadowOf(Looper.getMainLooper()).idle();
    assertThat(prerollAdMediaSource.isPrepared()).isTrue();
    verify(mockMediaSourceCaller).onSourceInfoRefreshed(adsMediaSource, new SinglePeriodAdTimeline(CONTENT_TIMELINE, AD_PLAYBACK_STATE));
}
Also used : Allocator(com.google.android.exoplayer2.upstream.Allocator) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 2 with SinglePeriodAdTimeline

use of com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline in project ExoPlayer by google.

the class MediaPeriodQueueTest method getNextMediaPeriodInfo_withServerSideInsertedAds_returnsCorrectMediaPeriodInfos.

@Test
public void getNextMediaPeriodInfo_withServerSideInsertedAds_returnsCorrectMediaPeriodInfos() {
    adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0, FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US).withContentDurationUs(CONTENT_DURATION_US).withIsServerSideInserted(/* adGroupIndex= */
    0, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    1, /* isServerSideInserted= */
    true).withIsServerSideInserted(/* adGroupIndex= */
    2, /* isServerSideInserted= */
    true);
    SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
    setupTimeline(adTimeline);
    setAdGroupLoaded(/* adGroupIndex= */
    0);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    0, AD_DURATION_US, /* contentPositionUs= */
    C.TIME_UNSET, /* isFollowedByTransitionToSameStream= */
    true);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    0, /* requestedContentPositionUs= */
    C.TIME_UNSET, /* endPositionUs= */
    FIRST_AD_START_TIME_US, /* durationUs= */
    FIRST_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    true, /* isLastInPeriod= */
    false, /* isLastInWindow= */
    false, /* nextAdGroupIndex= */
    1);
    advance();
    setAdGroupLoaded(/* adGroupIndex= */
    1);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    1, AD_DURATION_US, /* contentPositionUs= */
    FIRST_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    true);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    FIRST_AD_START_TIME_US, /* requestedContentPositionUs= */
    FIRST_AD_START_TIME_US, /* endPositionUs= */
    SECOND_AD_START_TIME_US, /* durationUs= */
    SECOND_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    true, /* isLastInPeriod= */
    false, /* isLastInWindow= */
    false, /* nextAdGroupIndex= */
    2);
    advance();
    setAdGroupLoaded(/* adGroupIndex= */
    2);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    2, AD_DURATION_US, /* contentPositionUs= */
    SECOND_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    true);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    SECOND_AD_START_TIME_US, /* requestedContentPositionUs= */
    SECOND_AD_START_TIME_US, /* endPositionUs= */
    CONTENT_DURATION_US, /* durationUs= */
    CONTENT_DURATION_US, /* isFollowedByTransitionToSameStream= */
    false, /* isLastInPeriod= */
    true, /* isLastInWindow= */
    true, /* nextAdGroupIndex= */
    C.INDEX_UNSET);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 3 with SinglePeriodAdTimeline

use of com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline in project ExoPlayer by google.

the class MediaPeriodQueueTest method getNextMediaPeriodInfo_withAdGroupResumeOffsets_returnsCorrectMediaPeriodInfos.

@Test
public void getNextMediaPeriodInfo_withAdGroupResumeOffsets_returnsCorrectMediaPeriodInfos() {
    adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    0, FIRST_AD_START_TIME_US, C.TIME_END_OF_SOURCE).withContentDurationUs(CONTENT_DURATION_US).withContentResumeOffsetUs(/* adGroupIndex= */
    0, /* contentResumeOffsetUs= */
    2000).withContentResumeOffsetUs(/* adGroupIndex= */
    1, /* contentResumeOffsetUs= */
    3000).withContentResumeOffsetUs(/* adGroupIndex= */
    2, /* contentResumeOffsetUs= */
    4000);
    SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
    setupTimeline(adTimeline);
    setAdGroupLoaded(/* adGroupIndex= */
    0);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    0, AD_DURATION_US, /* contentPositionUs= */
    C.TIME_UNSET, /* isFollowedByTransitionToSameStream= */
    false);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    2000, /* requestedContentPositionUs= */
    C.TIME_UNSET, /* endPositionUs= */
    FIRST_AD_START_TIME_US, /* durationUs= */
    FIRST_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    false, /* isLastInPeriod= */
    false, /* isLastInWindow= */
    false, /* nextAdGroupIndex= */
    1);
    advance();
    setAdGroupLoaded(/* adGroupIndex= */
    1);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    1, AD_DURATION_US, /* contentPositionUs= */
    FIRST_AD_START_TIME_US, /* isFollowedByTransitionToSameStream= */
    false);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    FIRST_AD_START_TIME_US + 3000, /* requestedContentPositionUs= */
    FIRST_AD_START_TIME_US, /* endPositionUs= */
    C.TIME_END_OF_SOURCE, /* durationUs= */
    CONTENT_DURATION_US, /* isFollowedByTransitionToSameStream= */
    false, /* isLastInPeriod= */
    false, /* isLastInWindow= */
    false, /* nextAdGroupIndex= */
    2);
    advance();
    setAdGroupLoaded(/* adGroupIndex= */
    2);
    assertNextMediaPeriodInfoIsAd(/* adGroupIndex= */
    2, AD_DURATION_US, /* contentPositionUs= */
    CONTENT_DURATION_US, /* isFollowedByTransitionToSameStream= */
    false);
    advance();
    assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(/* periodUid= */
    firstPeriodUid, /* startPositionUs= */
    CONTENT_DURATION_US - 1, /* requestedContentPositionUs= */
    CONTENT_DURATION_US, /* endPositionUs= */
    C.TIME_UNSET, /* durationUs= */
    CONTENT_DURATION_US, /* isFollowedByTransitionToSameStream= */
    false, /* isLastInPeriod= */
    true, /* isLastInWindow= */
    true, /* nextAdGroupIndex= */
    C.INDEX_UNSET);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 4 with SinglePeriodAdTimeline

use of com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline in project ExoPlayer by google.

the class MediaPeriodQueueTest method updateQueuedPeriods_withDurationChangeInPlayingContentAfterReadingPositionInServerSideInsertedAd_handlesChangeAndRemovesPeriodsAfterChangedPeriod.

@Test
public void updateQueuedPeriods_withDurationChangeInPlayingContentAfterReadingPositionInServerSideInsertedAd_handlesChangeAndRemovesPeriodsAfterChangedPeriod() {
    adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimes... */
    FIRST_AD_START_TIME_US).withIsServerSideInserted(/* adGroupIndex= */
    0, /* isServerSideInserted= */
    true);
    SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
    setupTimeline(adTimeline);
    setAdGroupLoaded(/* adGroupIndex= */
    0);
    // Content before ad.
    enqueueNext();
    // Ad.
    enqueueNext();
    // Content after ad.
    enqueueNext();
    // Change position of first ad (= change duration of playing content before first ad).
    adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), /* adGroupTimesUs...= */
    FIRST_AD_START_TIME_US - 2000).withIsServerSideInserted(/* adGroupIndex= */
    0, /* isServerSideInserted= */
    true);
    updateTimeline();
    setAdGroupLoaded(/* adGroupIndex= */
    0);
    long maxRendererReadPositionUs = MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US + FIRST_AD_START_TIME_US - 1000;
    boolean changeHandled = mediaPeriodQueue.updateQueuedPeriods(playbackInfo.timeline, /* rendererPositionUs= */
    MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US, maxRendererReadPositionUs);
    assertThat(changeHandled).isTrue();
    assertThat(getQueueLength()).isEqualTo(1);
    assertThat(mediaPeriodQueue.getPlayingPeriod().info.endPositionUs).isEqualTo(FIRST_AD_START_TIME_US - 2000);
    assertThat(mediaPeriodQueue.getPlayingPeriod().info.durationUs).isEqualTo(FIRST_AD_START_TIME_US - 2000);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 5 with SinglePeriodAdTimeline

use of com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline in project ExoPlayer by google.

the class MediaPeriodQueueTest method updateTimeline.

private void updateTimeline() {
    SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
    fakeMediaSource.setNewSourceInfo(adTimeline);
    // Progress the looper so that the source info events have been executed.
    shadowOf(Looper.getMainLooper()).idle();
    playbackInfo = playbackInfo.copyWithTimeline(mediaSourceList.createTimeline());
}
Also used : SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline)

Aggregations

SinglePeriodAdTimeline (com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline)5 Test (org.junit.Test)5 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)4 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)2 Allocator (com.google.android.exoplayer2.upstream.Allocator)2 Nullable (androidx.annotation.Nullable)1 Timeline (com.google.android.exoplayer2.Timeline)1