Search in sources :

Example 1 with AdOverlayInfo

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

the class ImaServerSideAdInsertionMediaSource method registerFriendlyObstructions.

private static void registerFriendlyObstructions(ImaSdkFactory imaSdkFactory, StreamDisplayContainer container, AdViewProvider adViewProvider) {
    for (int i = 0; i < adViewProvider.getAdOverlayInfos().size(); i++) {
        AdOverlayInfo overlayInfo = adViewProvider.getAdOverlayInfos().get(i);
        container.registerFriendlyObstruction(imaSdkFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
    }
}
Also used : AdOverlayInfo(com.google.android.exoplayer2.ui.AdOverlayInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Example 2 with AdOverlayInfo

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

the class AdTagLoader method addListenerWithAdView.

/**
 * Starts passing events from this instance (including any pending ad playback state) and
 * registers obstructions.
 */
public void addListenerWithAdView(EventListener eventListener, AdViewProvider adViewProvider) {
    boolean isStarted = !eventListeners.isEmpty();
    eventListeners.add(eventListener);
    if (isStarted) {
        if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
            // Pass the existing ad playback state to the new listener.
            eventListener.onAdPlaybackState(adPlaybackState);
        }
        return;
    }
    lastVolumePercent = 0;
    lastAdProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
    lastContentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
    maybeNotifyPendingAdLoadError();
    if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
        // Pass the ad playback state to the player, and resume ads if necessary.
        eventListener.onAdPlaybackState(adPlaybackState);
    } else if (adsManager != null) {
        adPlaybackState = new AdPlaybackState(adsId, getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
        updateAdPlaybackState();
    }
    for (AdOverlayInfo overlayInfo : adViewProvider.getAdOverlayInfos()) {
        adDisplayContainer.registerFriendlyObstruction(imaFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail));
    }
}
Also used : AdOverlayInfo(com.google.android.exoplayer2.ui.AdOverlayInfo) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState)

Example 3 with AdOverlayInfo

use of com.google.android.exoplayer2.ui.AdOverlayInfo 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)

Aggregations

AdOverlayInfo (com.google.android.exoplayer2.ui.AdOverlayInfo)3 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 CuePoint (com.google.ads.interactivemedia.v3.api.CuePoint)1 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)1 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)1 AdViewProvider (com.google.android.exoplayer2.ui.AdViewProvider)1 ImmutableList (com.google.common.collect.ImmutableList)1 Before (org.junit.Before)1