From cfcbd2114ba43a7a906577981e383a264d437929 Mon Sep 17 00:00:00 2001 From: ogaclejapan Date: Sun, 21 Oct 2018 13:54:07 +0900 Subject: [PATCH] Allow setting the ad UI elements to be rendered in ImaAdsLoader --- .../exoplayer2/ext/ima/ImaAdsLoader.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java index 581964ae47..e42f2853b2 100644 --- a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java +++ b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java @@ -40,6 +40,7 @@ import com.google.ads.interactivemedia.v3.api.AdsRequest; import com.google.ads.interactivemedia.v3.api.CompanionAdSlot; import com.google.ads.interactivemedia.v3.api.ImaSdkFactory; import com.google.ads.interactivemedia.v3.api.ImaSdkSettings; +import com.google.ads.interactivemedia.v3.api.UiElement; import com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider; import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer; import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate; @@ -69,6 +70,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; /** Loads ads using the IMA SDK. All methods are called on the main thread. */ public final class ImaAdsLoader @@ -91,6 +93,7 @@ public final class ImaAdsLoader private @Nullable ImaSdkSettings imaSdkSettings; private @Nullable AdEventListener adEventListener; + private @Nullable Set adUiElements; private int vastLoadTimeoutMs; private int mediaLoadTimeoutMs; private int mediaBitrateKbps; @@ -135,6 +138,18 @@ public final class ImaAdsLoader return this; } + /** + * Sets the ad UI elements to be rendered by the IMA SDK. + * + * @param adUiElements The ad UI elements to be rendered by the IMA SDK. + * @return This builder, for convenience. + * @see AdsRenderingSettings#setUiElements(Set) + */ + public Builder setAdUiElements(Set adUiElements) { + this.adUiElements = Assertions.checkNotNull(adUiElements); + return this; + } + /** * Sets the VAST load timeout, in milliseconds. * @@ -197,6 +212,7 @@ public final class ImaAdsLoader vastLoadTimeoutMs, mediaLoadTimeoutMs, mediaBitrateKbps, + adUiElements, adEventListener, imaFactory); } @@ -217,6 +233,7 @@ public final class ImaAdsLoader vastLoadTimeoutMs, mediaLoadTimeoutMs, mediaBitrateKbps, + adUiElements, adEventListener, imaFactory); } @@ -271,6 +288,7 @@ public final class ImaAdsLoader private final int vastLoadTimeoutMs; private final int mediaLoadTimeoutMs; private final int mediaBitrateKbps; + private final @Nullable Set adUiElements; private final @Nullable AdEventListener adEventListener; private final ImaFactory imaFactory; private final Timeline.Period period; @@ -358,6 +376,7 @@ public final class ImaAdsLoader /* vastLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaBitrateKpbs= */ BITRATE_UNSET, + /* adUiElements= */ null, /* adEventListener= */ null, /* imaFactory= */ new DefaultImaFactory()); } @@ -383,6 +402,7 @@ public final class ImaAdsLoader /* vastLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaBitrateKbps= */ BITRATE_UNSET, + /* adUiElements= */ null, /* adEventListener= */ null, /* imaFactory= */ new DefaultImaFactory()); } @@ -395,6 +415,7 @@ public final class ImaAdsLoader int vastLoadTimeoutMs, int mediaLoadTimeoutMs, int mediaBitrateKbps, + @Nullable Set adUiElements, @Nullable AdEventListener adEventListener, ImaFactory imaFactory) { Assertions.checkArgument(adTagUri != null || adsResponse != null); @@ -403,6 +424,7 @@ public final class ImaAdsLoader this.vastLoadTimeoutMs = vastLoadTimeoutMs; this.mediaLoadTimeoutMs = mediaLoadTimeoutMs; this.mediaBitrateKbps = mediaBitrateKbps; + this.adUiElements = adUiElements; this.adEventListener = adEventListener; this.imaFactory = imaFactory; if (imaSdkSettings == null) { @@ -952,6 +974,9 @@ public final class ImaAdsLoader if (mediaBitrateKbps != BITRATE_UNSET) { adsRenderingSettings.setBitrateKbps(mediaBitrateKbps); } + if (adUiElements != null) { + adsRenderingSettings.setUiElements(adUiElements); + } // Set up the ad playback state, skipping ads based on the start position as required. long[] adGroupTimesUs = getAdGroupTimesUs(adsManager.getAdCuePoints());