use of androidx.media3.exoplayer.source.ads.AdsMediaSource in project media by androidx.
the class ImaAdsLoaderTest method requestAdTagWithDataScheme_requestsWithAdsResponse.
@Test
public void requestAdTagWithDataScheme_requestsWithAdsResponse() throws Exception {
String adsResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<VAST xmlns:xsi=\"https://www.w3.org/2001/XMLSchema-instance\"" + " xsi:noNamespaceSchemaLocation=\"vast.xsd\" version=\"2.0\">\n" + " <Ad id=\"17180293\">\n" + " <InLine></InLine>\n" + " </Ad>\n" + "</VAST>";
DataSpec adDataSpec = new DataSpec(Util.getDataUriForString("text/xml", adsResponse));
imaAdsLoader.start(adsMediaSource, adDataSpec, TEST_ADS_ID, adViewProvider, adsLoaderListener);
verify(mockAdsRequest).setAdsResponse(adsResponse);
}
use of androidx.media3.exoplayer.source.ads.AdsMediaSource in project media by androidx.
the class ImaAdsLoaderTest method playback_withPrerollAd_marksAdAsPlayed.
@Test
public void playback_withPrerollAd_marksAdAsPlayed() {
// Load the preroll ad.
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));
// Play the preroll ad.
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));
// Play the content.
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, /* positionMs= */
0);
videoAdPlayer.stopAd(TEST_AD_MEDIA_INFO);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */
null));
// 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));
}
use of androidx.media3.exoplayer.source.ads.AdsMediaSource in project media by androidx.
the class ImaAdsLoaderTest method startAndCallbacksAfterRelease.
@Test
public void startAndCallbacksAfterRelease() {
// Request ads in order to get a reference to the ad event listener.
imaAdsLoader.requestAds(TEST_DATA_SPEC, TEST_ADS_ID, adViewGroup);
imaAdsLoader.release();
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, /* positionMs= */
0);
fakePlayer.setState(Player.STATE_READY, /* playWhenReady= */
true);
// If callbacks are invoked there is no crash.
// Note: we can't currently call getContentProgress/getAdProgress as a VerifyError is thrown
// when using Robolectric and accessing VideoProgressUpdate.VIDEO_TIME_NOT_READY, due to the IMA
// SDK being proguarded.
imaAdsLoader.requestAds(TEST_DATA_SPEC, TEST_ADS_ID, adViewGroup);
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);
adEventListener.onAdEvent(getAdEvent(AdEventType.STARTED, mockPrerollSingleAd));
videoAdPlayer.pauseAd(TEST_AD_MEDIA_INFO);
videoAdPlayer.stopAd(TEST_AD_MEDIA_INFO);
ExoPlaybackException anException = ExoPlaybackException.createForSource(new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
fakePlayer.setPlayerError(anException);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */
null));
imaAdsLoader.handlePrepareError(adsMediaSource, /* adGroupIndex= */
0, /* adIndexInAdGroup= */
0, new IOException());
}
use of androidx.media3.exoplayer.source.ads.AdsMediaSource in project media by androidx.
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));
}
use of androidx.media3.exoplayer.source.ads.AdsMediaSource in project media by androidx.
the class ImaAdsLoaderTest method resumePlaybackAfterMidroll_withoutPlayAdBeforeStartPosition_skipsMidroll.
@Test
public void resumePlaybackAfterMidroll_withoutPlayAdBeforeStartPosition_skipsMidroll() {
imaAdsLoader = new ImaAdsLoader.Builder(getApplicationContext()).setPlayAdBeforeStartPosition(false).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);
long midrollWindowTimeUs = 2 * C.MICROS_PER_SECOND;
long midrollPeriodTimeUs = midrollWindowTimeUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
ImmutableList<Float> cuePoints = ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition(/* periodIndex= */
0, Util.usToMs(midrollWindowTimeUs) + 1_000);
imaAdsLoader.start(adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
verify(mockAdsManager).destroy();
assertThat(getAdPlaybackState(/* periodIndex= */
0)).isEqualTo(new AdPlaybackState(TEST_ADS_ID, getAdGroupTimesUsForCuePoints(cuePoints)).withContentDurationUs(CONTENT_PERIOD_DURATION_US).withSkippedAdGroup(/* adGroupIndex= */
0).withSkippedAdGroup(/* adGroupIndex= */
1));
}
Aggregations