Search in sources :

Example 1 with SinglePeriodAdTimeline

use of androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline in project media by androidx.

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(androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline)

Example 2 with SinglePeriodAdTimeline

use of androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline in project media by androidx.

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(androidx.media3.common.AdPlaybackState) SinglePeriodAdTimeline(androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 3 with SinglePeriodAdTimeline

use of androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline in project media by androidx.

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(androidx.media3.common.AdPlaybackState) SinglePeriodAdTimeline(androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 4 with SinglePeriodAdTimeline

use of androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline in project media by androidx.

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(androidx.media3.common.AdPlaybackState) SinglePeriodAdTimeline(androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline) Test(org.junit.Test)

Example 5 with SinglePeriodAdTimeline

use of androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline in project media by androidx.

the class MediaPeriodQueueTest method setupAdTimeline.

private void setupAdTimeline(long... adGroupTimesUs) {
    adPlaybackState = new AdPlaybackState(/* adsId= */
    new Object(), adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US);
    SinglePeriodAdTimeline adTimeline = new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
    setupTimeline(adTimeline);
}
Also used : AdPlaybackState(androidx.media3.common.AdPlaybackState) SinglePeriodAdTimeline(androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline)

Aggregations

SinglePeriodAdTimeline (androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline)5 Test (org.junit.Test)5 AdPlaybackState (androidx.media3.common.AdPlaybackState)4 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)2 Allocator (androidx.media3.exoplayer.upstream.Allocator)2 Nullable (androidx.annotation.Nullable)1 Timeline (androidx.media3.common.Timeline)1