/** * 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 Object getUserRequestContext() { return adsRequest.getUserRequestContext(); } });
@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); }