Search in sources :

Example 1 with AdEvent

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

the class ImaAdsLoaderTest method playback_withMidrollFetchError_marksAdAsInErrorState.

@Test
public void playback_withMidrollFetchError_marksAdAsInErrorState() {
    AdEvent mockMidrollFetchErrorAdEvent = mock(AdEvent.class);
    when(mockMidrollFetchErrorAdEvent.getType()).thenReturn(AdEventType.AD_BREAK_FETCH_ERROR);
    when(mockMidrollFetchErrorAdEvent.getAdData()).thenReturn(ImmutableMap.of("adBreakTime", "20.5"));
    when(mockAdsManager.getAdCuePoints()).thenReturn(ImmutableList.of(20.5f));
    // Simulate loading an empty midroll ad.
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    adEventListener.onAdEvent(mockMidrollFetchErrorAdEvent);
    assertThat(getAdPlaybackState(/* periodIndex= */
    0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */
    20_500_000).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdLoadError(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0));
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdEvent(com.google.ads.interactivemedia.v3.api.AdEvent) Test(org.junit.Test)

Example 2 with AdEvent

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

the class ImaAdsLoaderTest method playback_withPostrollFetchError_marksAdAsInErrorState.

@Test
public void playback_withPostrollFetchError_marksAdAsInErrorState() {
    AdEvent mockPostrollFetchErrorAdEvent = mock(AdEvent.class);
    when(mockPostrollFetchErrorAdEvent.getType()).thenReturn(AdEventType.AD_BREAK_FETCH_ERROR);
    when(mockPostrollFetchErrorAdEvent.getAdData()).thenReturn(ImmutableMap.of("adBreakTime", "-1"));
    when(mockAdsManager.getAdCuePoints()).thenReturn(ImmutableList.of(-1f));
    // Simulate loading an empty postroll ad.
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    adEventListener.onAdEvent(mockPostrollFetchErrorAdEvent);
    assertThat(getAdPlaybackState(/* periodIndex= */
    0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */
    C.TIME_END_OF_SOURCE).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withAdCount(/* adGroupIndex= */
    0, /* adCount= */
    1).withAdLoadError(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0));
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdEvent(com.google.ads.interactivemedia.v3.api.AdEvent) Test(org.junit.Test)

Example 3 with AdEvent

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

the class ImaAdsLoaderTest method playback_withMidrollFetchError_updatesContentProgress.

@Test
public void playback_withMidrollFetchError_updatesContentProgress() {
    AdEvent mockMidrollFetchErrorAdEvent = mock(AdEvent.class);
    when(mockMidrollFetchErrorAdEvent.getType()).thenReturn(AdEventType.AD_BREAK_FETCH_ERROR);
    when(mockMidrollFetchErrorAdEvent.getAdData()).thenReturn(ImmutableMap.of("adBreakTime", "5.5"));
    when(mockAdsManager.getAdCuePoints()).thenReturn(ImmutableList.of(5.5f));
    // Simulate loading an empty midroll ad and advancing the player position.
    imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
    adEventListener.onAdEvent(mockMidrollFetchErrorAdEvent);
    long playerPositionUs = CONTENT_DURATION_US - C.MICROS_PER_SECOND;
    long playerPositionInPeriodUs = playerPositionUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
    long periodDurationUs = CONTENT_TIMELINE.getPeriod(/* periodIndex= */
    0, new Period()).durationUs;
    fakePlayer.setPlayingContentPosition(/* periodIndex= */
    0, Util.usToMs(playerPositionUs));
    // Verify the content progress is updated to reflect the new player position.
    assertThat(contentProgressProvider.getContentProgress()).isEqualTo(new VideoProgressUpdate(Util.usToMs(playerPositionInPeriodUs), Util.usToMs(periodDurationUs)));
}
Also used : Period(com.google.android.exoplayer2.Timeline.Period) AdEvent(com.google.ads.interactivemedia.v3.api.AdEvent) VideoProgressUpdate(com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate) Test(org.junit.Test)

Aggregations

AdEvent (com.google.ads.interactivemedia.v3.api.AdEvent)3 Test (org.junit.Test)3 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)2 VideoProgressUpdate (com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate)1 Period (com.google.android.exoplayer2.Timeline.Period)1