Search in sources :

Example 31 with AdsMediaSource

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

the class ImaAdsLoaderTest method resumePlaybackAtSecondMidroll_skipsFirstMidroll.

@Test
public void resumePlaybackAtSecondMidroll_skipsFirstMidroll() {
    long firstMidrollWindowTimeUs = 2 * C.MICROS_PER_SECOND;
    long firstMidrollPeriodTimeUs = firstMidrollWindowTimeUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    long secondMidrollWindowTimeUs = 4 * C.MICROS_PER_SECOND;
    long secondMidrollPeriodTimeUs = secondMidrollWindowTimeUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    ImmutableList<Float> cuePoints = ImmutableList.of((float) firstMidrollPeriodTimeUs / C.MICROS_PER_SECOND, (float) secondMidrollPeriodTimeUs / C.MICROS_PER_SECOND);
    when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
    fakePlayer.setPlayingContentPosition(/* periodIndex= */
    0, Util.usToMs(secondMidrollWindowTimeUs));
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    ArgumentCaptor<Double> playAdsAfterTimeCaptor = ArgumentCaptor.forClass(Double.class);
    verify(mockAdsRenderingSettings).setPlayAdsAfterTime(playAdsAfterTimeCaptor.capture());
    double expectedPlayAdsAfterTimeUs = (firstMidrollPeriodTimeUs + secondMidrollPeriodTimeUs) / 2d;
    assertThat(playAdsAfterTimeCaptor.getValue()).isWithin(0.1).of(expectedPlayAdsAfterTimeUs / C.MICROS_PER_SECOND);
    assertThat(getAdPlaybackState(/* periodIndex= */
    0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withSkippedAdGroup(/* adGroupIndex= */
    0));
}
Also used : AdPlaybackState(androidx.media3.common.AdPlaybackState) ArgumentMatchers.anyDouble(org.mockito.ArgumentMatchers.anyDouble) Test(org.junit.Test)

Example 32 with AdsMediaSource

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

the class ImaAdsLoader method start.

@UnstableApi
@Override
public void start(AdsMediaSource adsMediaSource, DataSpec adTagDataSpec, Object adsId, AdViewProvider adViewProvider, EventListener eventListener) {
    checkState(wasSetPlayerCalled, "Set player using adsLoader.setPlayer before preparing the player.");
    if (adTagLoaderByAdsMediaSource.isEmpty()) {
        player = nextPlayer;
        @Nullable Player player = this.player;
        if (player == null) {
            return;
        }
        player.addListener(playerListener);
    }
    @Nullable AdTagLoader adTagLoader = adTagLoaderByAdsId.get(adsId);
    if (adTagLoader == null) {
        requestAds(adTagDataSpec, adsId, adViewProvider.getAdViewGroup());
        adTagLoader = adTagLoaderByAdsId.get(adsId);
    }
    adTagLoaderByAdsMediaSource.put(adsMediaSource, checkNotNull(adTagLoader));
    adTagLoader.addListenerWithAdView(eventListener, adViewProvider);
    maybeUpdateCurrentAdTagLoader();
}
Also used : VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Player(androidx.media3.common.Player) Nullable(androidx.annotation.Nullable) UnstableApi(androidx.media3.common.util.UnstableApi)

Aggregations

Test (org.junit.Test)28 AdPlaybackState (androidx.media3.common.AdPlaybackState)19 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)16 AdsMediaSource (androidx.media3.exoplayer.source.ads.AdsMediaSource)13 DefaultMediaSourceFactory (androidx.media3.exoplayer.source.DefaultMediaSourceFactory)12 ArgumentMatchers.anyDouble (org.mockito.ArgumentMatchers.anyDouble)7 Context (android.content.Context)3 AdViewProvider (androidx.media3.common.AdViewProvider)3 Timeline (androidx.media3.common.Timeline)3 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)3 ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState)3 FakeTimeline (androidx.media3.test.utils.FakeTimeline)3 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)3 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)3 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)3 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)3 AdEvent (com.google.ads.interactivemedia.v3.api.AdEvent)3 Nullable (androidx.annotation.Nullable)2 MediaItem (androidx.media3.common.MediaItem)2 DataSpec (androidx.media3.datasource.DataSpec)2