use of com.google.android.exoplayer2.ext.ima.ImaAdsLoader in project ExoPlayer by google.
the class ImaAdsLoaderTest method setUp.
@Before
public void setUp() {
setupMocks();
fakePlayer = new FakeExoPlayer();
adViewGroup = new FrameLayout(getApplicationContext());
View adOverlayView = new View(getApplicationContext());
adViewProvider = new AdViewProvider() {
@Override
public ViewGroup getAdViewGroup() {
return adViewGroup;
}
@Override
public ImmutableList<AdOverlayInfo> getAdOverlayInfos() {
return ImmutableList.of(new AdOverlayInfo(adOverlayView, AdOverlayInfo.PURPOSE_CLOSE_AD));
}
};
audioAdsAdViewProvider = () -> null;
imaAdsLoader = new ImaAdsLoader.Builder(getApplicationContext()).setImaFactory(mockImaFactory).setImaSdkSettings(mockImaSdkSettings).setVideoAdPlayerCallback(mockVideoAdPlayerCallback).build();
imaAdsLoader.setPlayer(fakePlayer);
adsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, TEST_ADS_ID, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
timelineWindowDefinitions = new TimelineWindowDefinition[] { getInitialTimelineWindowDefinition(TEST_ADS_ID) };
adsLoaderListener = new TestAdsLoaderListener(/* periodIndex= */
0);
when(mockAdsManager.getAdCuePoints()).thenReturn(PREROLL_CUE_POINTS_SECONDS);
}
use of com.google.android.exoplayer2.ext.ima.ImaAdsLoader in project ExoPlayer by google.
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