/** * 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); }
/** * 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); }