Search in sources :

Example 1 with AdPodInfo

use of com.google.ads.interactivemedia.v3.api.AdPodInfo in project ExoPlayer by google.

the class ImaAdsLoaderTest method loadAd_withLargeAdCuePoint_updatesAdPlaybackStateWithLoadedAd.

@Test
public void loadAd_withLargeAdCuePoint_updatesAdPlaybackStateWithLoadedAd() {
    // Use a large enough value to test correct truncating of large cue points.
    float midrollTimeSecs = Float.MAX_VALUE;
    List<Float> cuePoints = ImmutableList.of(midrollTimeSecs);
    when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    videoAdPlayer.loadAd(TEST_AD_MEDIA_INFO, new AdPodInfo() {

        @Override
        public int getTotalAds() {
            return 1;
        }

        @Override
        public int getAdPosition() {
            return 1;
        }

        @Override
        public boolean isBumper() {
            return false;
        }

        @Override
        public double getMaxDuration() {
            return 0;
        }

        @Override
        public int getPodIndex() {
            return 0;
        }

        @Override
        public double getTimeOffset() {
            return midrollTimeSecs;
        }
    });
    assertThat(getAdPlaybackState(/* periodIndex= */
    0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdUri(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, TEST_URI).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }));
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdPodInfo(com.google.ads.interactivemedia.v3.api.AdPodInfo) Test(org.junit.Test)

Example 2 with AdPodInfo

use of com.google.ads.interactivemedia.v3.api.AdPodInfo in project ExoPlayer by google.

the class ImaServerSideAdInsertionMediaSource method skipAd.

private static AdPlaybackState skipAd(Ad ad, AdPlaybackState adPlaybackState) {
    AdPodInfo adPodInfo = ad.getAdPodInfo();
    int adGroupIndex = adPodInfo.getPodIndex();
    // IMA SDK always returns index starting at 1.
    int adIndexInAdGroup = adPodInfo.getAdPosition() - 1;
    return adPlaybackState.withSkippedAd(adGroupIndex, adIndexInAdGroup);
}
Also used : AdPodInfo(com.google.ads.interactivemedia.v3.api.AdPodInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Example 3 with AdPodInfo

use of com.google.ads.interactivemedia.v3.api.AdPodInfo in project ExoPlayer by google.

the class ImaServerSideAdInsertionMediaSource method addLiveAdBreak.

private static AdPlaybackState addLiveAdBreak(Ad ad, long currentPeriodPositionUs, AdPlaybackState adPlaybackState) {
    AdPodInfo adPodInfo = ad.getAdPodInfo();
    long adDurationUs = secToUs(ad.getDuration());
    int adIndexInAdGroup = adPodInfo.getAdPosition() - 1;
    // TODO(b/208398934) Support seeking backwards.
    if (adIndexInAdGroup == 0 || adPlaybackState.adGroupCount == 1) {
        // First ad of group. Create a new group with all ads.
        long[] adDurationsUs = updateAdDurationAndPropagate(new long[adPodInfo.getTotalAds()], adIndexInAdGroup, adDurationUs, secToUs(adPodInfo.getMaxDuration()));
        adPlaybackState = addAdGroupToAdPlaybackState(adPlaybackState, /* fromPositionUs= */
        currentPeriodPositionUs, /* contentResumeOffsetUs= */
        sum(adDurationsUs), /* adDurationsUs...= */
        adDurationsUs);
    } else {
        int adGroupIndex = adPlaybackState.adGroupCount - 2;
        adPlaybackState = updateAdDurationInAdGroup(adGroupIndex, adIndexInAdGroup, adDurationUs, adPlaybackState);
        AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(adGroupIndex);
        return adPlaybackState.withContentResumeOffsetUs(adGroupIndex, min(adGroup.contentResumeOffsetUs, sum(adGroup.durationsUs)));
    }
    return adPlaybackState;
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdPodInfo(com.google.ads.interactivemedia.v3.api.AdPodInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Example 4 with AdPodInfo

use of com.google.ads.interactivemedia.v3.api.AdPodInfo in project ExoPlayer by google.

the class ImaServerSideAdInsertionMediaSource method setVodAdInPlaceholder.

private static AdPlaybackState setVodAdInPlaceholder(Ad ad, AdPlaybackState adPlaybackState) {
    AdPodInfo adPodInfo = ad.getAdPodInfo();
    // Handle post rolls that have a podIndex of -1.
    int adGroupIndex = adPodInfo.getPodIndex() == -1 ? adPlaybackState.adGroupCount - 1 : adPodInfo.getPodIndex();
    AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(adGroupIndex);
    int adIndexInAdGroup = adPodInfo.getAdPosition() - 1;
    if (adGroup.count < adPodInfo.getTotalAds()) {
        adPlaybackState = expandAdGroupPlaceholder(adGroupIndex, /* adGroupDurationUs= */
        secToUs(adPodInfo.getMaxDuration()), adIndexInAdGroup, /* adDurationUs= */
        secToUs(ad.getDuration()), /* adsInAdGroupCount= */
        adPodInfo.getTotalAds(), adPlaybackState);
    } else if (adIndexInAdGroup < adGroup.count - 1) {
        adPlaybackState = updateAdDurationInAdGroup(adGroupIndex, adIndexInAdGroup, /* adDurationUs= */
        secToUs(ad.getDuration()), adPlaybackState);
    }
    return adPlaybackState;
}
Also used : ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdPodInfo(com.google.ads.interactivemedia.v3.api.AdPodInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Aggregations

AdPodInfo (com.google.ads.interactivemedia.v3.api.AdPodInfo)4 CuePoint (com.google.ads.interactivemedia.v3.api.CuePoint)3 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)3 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)2 Test (org.junit.Test)1