@Test public void testAttachPlayer_setsAdUiViewGroup() { setupPlayback(CONTENT_TIMELINE, PREROLL_ADS_DURATIONS_US, PREROLL_CUE_POINTS_SECONDS); imaAdsLoader.attachPlayer(fakeExoPlayer, adsLoaderListener, adUiViewGroup); verify(adDisplayContainer, atLeastOnce()).setAdContainer(adUiViewGroup); }
/** * Requests ads, if they have not already been requested. Must be called on the main thread. * * <p>Ads will be requested automatically when the player is prepared if this method has not been * called, so it is only necessary to call this method if you want to request ads before preparing * the player. * * @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI. */ public void requestAds(ViewGroup adUiViewGroup) { if (adPlaybackState != null || adsManager != null || pendingAdRequestContext != null) { // Ads have already been requested. return; } adDisplayContainer.setAdContainer(adUiViewGroup); pendingAdRequestContext = new Object(); AdsRequest request = imaFactory.createAdsRequest(); if (adTagUri != null) { request.setAdTagUrl(adTagUri.toString()); } else /* adsResponse != null */ { request.setAdsResponse(adsResponse); } if (vastLoadTimeoutMs != TIMEOUT_UNSET) { request.setVastLoadTimeout(vastLoadTimeoutMs); } request.setAdDisplayContainer(adDisplayContainer); request.setContentProgressProvider(this); request.setUserRequestContext(pendingAdRequestContext); adsLoader.requestAds(request); }
@Override public void attachPlayer(ExoPlayer player, EventListener eventListener, ViewGroup adUiViewGroup) { Assertions.checkArgument(player.getApplicationLooper() == Looper.getMainLooper()); this.player = player; this.eventListener = eventListener; lastVolumePercentage = 0; lastAdProgress = null; lastContentProgress = null; adDisplayContainer.setAdContainer(adUiViewGroup); player.addListener(this); maybeNotifyPendingAdLoadError(); if (adPlaybackState != null) { // Pass the ad playback state to the player, and resume ads if necessary. eventListener.onAdPlaybackState(adPlaybackState); if (imaPausedContent && player.getPlayWhenReady()) { adsManager.resume(); } } else if (adsManager != null) { // Ads have loaded but the ads manager is not initialized. startAdPlayback(); } else { // Ads haven't loaded yet, so request them. requestAds(adUiViewGroup); } }
@Override public void processEvent(Event event) { // Create a container object for the ads to be presented. AdDisplayContainer container = sdkFactory.createAdDisplayContainer(); container.setPlayer(googleIMAComponent.getVideoAdPlayer()); container.setAdContainer(brightcoveVideoView); // Build an ads request object and point it to the ad // display container created above. AdsRequest adsRequest = sdkFactory.createAdsRequest(); adsRequest.setAdTagUrl(adRulesURL); adsRequest.setAdDisplayContainer(container); ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1); adsRequests.add(adsRequest); // Respond to the event with the new ad requests. event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests); eventEmitter.respond(event); } });
@Override public void processEvent(Event event) { // Create a container object for the ads to be presented. AdDisplayContainer container = sdkFactory.createAdDisplayContainer(); container.setPlayer(googleIMAComponent.getVideoAdPlayer()); container.setAdContainer(brightcoveVideoView); // Build an ads request object and point it to the ad // display container created above. AdsRequest adsRequest = sdkFactory.createAdsRequest(); adsRequest.setAdTagUrl(adRulesURL); adsRequest.setAdDisplayContainer(container); ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1); adsRequests.add(adsRequest); // Respond to the event with the new ad requests. event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests); eventEmitter.respond(event); } });
/** * Requests video ads from the given VAST ad tag. * * @param adRequestUrl URL of the ad's VAST XML. */ public void requestAds(@NonNull String adRequestUrl, @NonNull AdControllerCallback adControllerCallback) { mAdControllerCallback = adControllerCallback; mAdDisplayContainer = mSdkFactory.createAdDisplayContainer(); mAdDisplayContainer.setPlayer(new VideoAdPlayerImpl()); mAdDisplayContainer.setAdContainer(mStubViewGroup); // Create the ads request. AdsRequest request = mSdkFactory.createAdsRequest(); request.setAdTagUrl(adRequestUrl); request.setAdDisplayContainer(mAdDisplayContainer); // Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called. mAdsLoader.requestAds(request); }