@Override public void release() { pendingAdRequestContext = null; if (adsManager != null) { adsManager.destroy(); adsManager = null; } adsLoader.removeAdsLoadedListener(/* adsLoadedListener= */ this); adsLoader.removeAdErrorListener(/* adErrorListener= */ this); imaPausedContent = false; imaAdState = IMA_AD_STATE_NONE; pendingAdLoadError = null; adPlaybackState = AdPlaybackState.NONE; updateAdPlaybackState(); }
private void checkForContentComplete() { if (contentDurationMs != C.TIME_UNSET && pendingContentPositionMs == C.TIME_UNSET && player.getContentPosition() + END_OF_CONTENT_POSITION_THRESHOLD_MS >= contentDurationMs && !sentContentComplete) { adsLoader.contentComplete(); if (DEBUG) { Log.d(TAG, "adsLoader.contentComplete"); } sentContentComplete = true; // After sending content complete IMA will not poll the content position, so set the expected // ad group index. expectedAdGroupIndex = adPlaybackState.getAdGroupIndexForPositionUs(C.msToUs(contentDurationMs)); } }
/** Builder for {@link ImaAdsLoader}. */ public static final class Builder { private final Context context; private @Nullable ImaSdkSettings imaSdkSettings; private @Nullable AdEventListener adEventListener; private @Nullable Set<UiElement> adUiElements; private int vastLoadTimeoutMs; private int mediaLoadTimeoutMs; private int mediaBitrate; private boolean focusSkipButtonWhenAvailable; private ImaFactory imaFactory; /** * Creates a new builder for {@link ImaAdsLoader}. * * @param context The context; */ public Builder(Context context) { this.context = Assertions.checkNotNull(context); vastLoadTimeoutMs = TIMEOUT_UNSET; mediaLoadTimeoutMs = TIMEOUT_UNSET; mediaBitrate = BITRATE_UNSET; focusSkipButtonWhenAvailable = true; imaFactory = new DefaultImaFactory(); } /** * Sets the IMA SDK settings. The provided settings instance's player type and version fields
/** * 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); }
public AdController(Context context) { // Create an AdsLoader. mSdkFactory = ImaSdkFactory.getInstance(); mAdsLoader = mSdkFactory.createAdsLoader(context); mAdsLoader.addAdErrorListener(this); mAdsLoader.addAdsLoadedListener(this); mStubViewGroup = new FrameLayout(context); }
/** * 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); }
/** * Releases related resources. */ public void release() { if (mAdsManager != null) { mAdsManager.destroy(); mAdsManager = null; } if (mAdsLoader != null) { mAdsLoader.removeAdsLoadedListener(this); mAdsLoader.removeAdErrorListener(this); } }