use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.
the class ImaAdsLoaderTest method playbackWithTwoAdsMediaSources_preloadsSecondAdTag.
@Test
public void playbackWithTwoAdsMediaSources_preloadsSecondAdTag() {
Object secondAdsId = new Object();
AdsMediaSource secondAdsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, secondAdsId, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
timelineWindowDefinitions = new TimelineWindowDefinition[] { getInitialTimelineWindowDefinition(TEST_ADS_ID), getInitialTimelineWindowDefinition(secondAdsId) };
TestAdsLoaderListener secondAdsLoaderListener = new TestAdsLoaderListener(/* periodIndex= */
1);
// Load and play the preroll ad then content.
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
adEventListener.onAdEvent(getAdEvent(AdEventType.LOADED, mockPrerollSingleAd));
videoAdPlayer.loadAd(TEST_AD_MEDIA_INFO, mockAdPodInfo);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_PAUSE_REQUESTED, mockPrerollSingleAd));
videoAdPlayer.playAd(TEST_AD_MEDIA_INFO);
fakePlayer.setPlayingAdPosition(/* periodIndex= */
0, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* position= */
0, /* contentPosition= */
0);
fakePlayer.setState(Player.STATE_READY, /* playWhenReady= */
true);
adEventListener.onAdEvent(getAdEvent(AdEventType.STARTED, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.FIRST_QUARTILE, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.MIDPOINT, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.THIRD_QUARTILE, mockPrerollSingleAd));
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, /* positionMs= */
0);
videoAdPlayer.stopAd(TEST_AD_MEDIA_INFO);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */
null));
// Simulate starting to buffer the second ads media source.
imaAdsLoader.start(secondAdsMediaSource, TEST_DATA_SPEC, secondAdsId, adViewProvider, secondAdsLoaderListener);
// Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */
0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */
0).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdUri(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, TEST_URI).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withPlayedAd(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0).withAdResumePositionUs(/* adResumePositionUs= */
0));
// Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */
1)).isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */
0));
}
use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.
the class ImaAdsLoaderTest method playbackWithTwoAdsMediaSources_preloadsSecondAdTagWithBackgroundResume.
@Test
public void playbackWithTwoAdsMediaSources_preloadsSecondAdTagWithBackgroundResume() {
Object secondAdsId = new Object();
AdsMediaSource secondAdsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, secondAdsId, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
timelineWindowDefinitions = new TimelineWindowDefinition[] { getInitialTimelineWindowDefinition(TEST_ADS_ID), getInitialTimelineWindowDefinition(secondAdsId) };
TestAdsLoaderListener secondAdsLoaderListener = new TestAdsLoaderListener(/* periodIndex= */
1);
// Load and play the preroll ad then content.
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
adEventListener.onAdEvent(getAdEvent(AdEventType.LOADED, mockPrerollSingleAd));
videoAdPlayer.loadAd(TEST_AD_MEDIA_INFO, mockAdPodInfo);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_PAUSE_REQUESTED, mockPrerollSingleAd));
videoAdPlayer.playAd(TEST_AD_MEDIA_INFO);
fakePlayer.setPlayingAdPosition(/* periodIndex= */
0, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, /* position= */
0, /* contentPosition= */
0);
fakePlayer.setState(Player.STATE_READY, /* playWhenReady= */
true);
adEventListener.onAdEvent(getAdEvent(AdEventType.STARTED, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.FIRST_QUARTILE, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.MIDPOINT, mockPrerollSingleAd));
adEventListener.onAdEvent(getAdEvent(AdEventType.THIRD_QUARTILE, mockPrerollSingleAd));
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, /* positionMs= */
0);
videoAdPlayer.stopAd(TEST_AD_MEDIA_INFO);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */
null));
// Simulate starting to buffer the second ads media source.
imaAdsLoader.start(secondAdsMediaSource, TEST_DATA_SPEC, secondAdsId, adViewProvider, secondAdsLoaderListener);
// Simulate backgrounding/resuming.
imaAdsLoader.stop(adsMediaSource, adsLoaderListener);
imaAdsLoader.stop(secondAdsMediaSource, secondAdsLoaderListener);
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
imaAdsLoader.start(secondAdsMediaSource, TEST_DATA_SPEC, secondAdsId, adViewProvider, secondAdsLoaderListener);
// Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */
0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */
0).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdUri(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, TEST_URI).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withPlayedAd(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0).withAdResumePositionUs(/* adResumePositionUs= */
0));
// Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */
1)).isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */
0));
}
use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.
the class ImaAdsLoaderTest method buildWithDefaultEnableContinuousPlayback_doesNotSetAdsRequestProperty.
@Test
public void buildWithDefaultEnableContinuousPlayback_doesNotSetAdsRequestProperty() {
imaAdsLoader = new ImaAdsLoader.Builder(getApplicationContext()).setImaFactory(mockImaFactory).setImaSdkSettings(mockImaSdkSettings).build();
imaAdsLoader.setPlayer(fakePlayer);
adsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, TEST_ADS_ID, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
when(mockAdsManager.getAdCuePoints()).thenReturn(PREROLL_CUE_POINTS_SECONDS);
imaAdsLoader.setSupportedContentTypes(C.TYPE_OTHER);
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
verify(mockAdsRequest, never()).setContinuousPlayback(anyBoolean());
}
use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.
the class ImaAdsLoaderTest method playback_withAdNotPreloadingAfterTimeout_hasErrorAdGroup.
@Test
public void playback_withAdNotPreloadingAfterTimeout_hasErrorAdGroup() {
// Simulate an ad at 2 seconds.
long adGroupPositionInWindowUs = 2 * C.MICROS_PER_SECOND;
long adGroupTimeUs = adGroupPositionInWindowUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
// Advance playback to just before the midroll and simulate buffering.
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, Util.usToMs(adGroupPositionInWindowUs));
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */
true);
// Advance past the timeout and simulate polling content progress.
ShadowSystemClock.advanceBy(Duration.ofSeconds(5));
contentProgressProvider.getContentProgress();
assertThat(getAdPlaybackState(/* periodIndex= */
0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdLoadError(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0));
}
use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.
the class ImaAdsLoaderTest method startPlaybackAfterMidroll_withAdNotPreloadingAfterTimeout_hasErrorAdGroup.
@Test
public void startPlaybackAfterMidroll_withAdNotPreloadingAfterTimeout_hasErrorAdGroup() {
// Simulate an ad at 2 seconds, and starting playback with an initial seek position at the ad.
long adGroupPositionInWindowUs = 2 * C.MICROS_PER_SECOND;
long adGroupTimeUs = adGroupPositionInWindowUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */
true);
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, Util.usToMs(adGroupPositionInWindowUs));
// Start ad loading while still buffering and poll progress without the ad loading.
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
contentProgressProvider.getContentProgress();
ShadowSystemClock.advanceBy(Duration.ofSeconds(5));
contentProgressProvider.getContentProgress();
assertThat(getAdPlaybackState(/* periodIndex= */
0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withAdDurationsUs(new long[][] { { TEST_AD_DURATION_US } }).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdLoadError(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0));
}
Aggregations