Search in sources :

Example 26 with AdViewProvider

use of com.google.android.exoplayer2.ui.AdViewProvider 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);
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ViewGroup(android.view.ViewGroup) ImmutableList(com.google.common.collect.ImmutableList) View(android.view.View) AdOverlayInfo(com.google.android.exoplayer2.ui.AdOverlayInfo) DefaultMediaSourceFactory(com.google.android.exoplayer2.source.DefaultMediaSourceFactory) FrameLayout(android.widget.FrameLayout) AdViewProvider(com.google.android.exoplayer2.ui.AdViewProvider) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) Before(org.junit.Before)

Example 27 with AdViewProvider

use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.

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());
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with AdViewProvider

use of com.google.android.exoplayer2.ui.AdViewProvider 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));
}
Also used : FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultMediaSourceFactory(com.google.android.exoplayer2.source.DefaultMediaSourceFactory) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) Test(org.junit.Test)

Example 29 with AdViewProvider

use of com.google.android.exoplayer2.ui.AdViewProvider in project ExoPlayer by google.

the class ImaAdsLoaderTest method resumePlaybackAtMidroll_skipsPreroll.

@Test
public void resumePlaybackAtMidroll_skipsPreroll() {
    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));
    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 = midrollPeriodTimeUs / 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(com.google.android.exoplayer2.source.ads.AdPlaybackState) ArgumentMatchers.anyDouble(org.mockito.ArgumentMatchers.anyDouble) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)17 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)12 ArgumentMatchers.anyDouble (org.mockito.ArgumentMatchers.anyDouble)7 Context (android.content.Context)3 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)3 AdEvent (com.google.ads.interactivemedia.v3.api.AdEvent)3 AdOverlayInfo (com.google.android.exoplayer2.ui.AdOverlayInfo)3 AdViewProvider (com.google.android.exoplayer2.ui.AdViewProvider)3 Nullable (androidx.annotation.Nullable)2 MediaItem (com.google.android.exoplayer2.MediaItem)2 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)2 Before (org.junit.Before)2 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 AdPodInfo (com.google.ads.interactivemedia.v3.api.AdPodInfo)1 CuePoint (com.google.ads.interactivemedia.v3.api.CuePoint)1