Commit fdbf16ed by andrewlewis Committed by Oliver Woodman

Allow setting the ad media load timeout in ImaAdsLoader

Issue: #3691

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192769801
parent 1944ebb4
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
* Support live stream clipping with `ClippingMediaSource`. * Support live stream clipping with `ClippingMediaSource`.
* Allow setting tags for all media sources in their factories. The tag of the * Allow setting tags for all media sources in their factories. The tag of the
current window can be retrieved with `ExoPlayer.getCurrentTag`. current window can be retrieved with `ExoPlayer.getCurrentTag`.
* IMA: Allow setting the ad media load timeout
([#3691](https://github.com/google/ExoPlayer/issues/3691)).
* Audio: * Audio:
* FLAC: Sniff FLAC files correctly if they have ID3 headers * FLAC: Sniff FLAC files correctly if they have ID3 headers
([#4055](https://github.com/google/ExoPlayer/issues/4055)). ([#4055](https://github.com/google/ExoPlayer/issues/4055)).
......
...@@ -80,7 +80,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -80,7 +80,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
private final Context context; private final Context context;
private @Nullable ImaSdkSettings imaSdkSettings; private @Nullable ImaSdkSettings imaSdkSettings;
private long vastLoadTimeoutMs; private int vastLoadTimeoutMs;
private int mediaLoadTimeoutMs;
/** /**
* Creates a new builder for {@link ImaAdsLoader}. * Creates a new builder for {@link ImaAdsLoader}.
...@@ -89,7 +90,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -89,7 +90,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
*/ */
public Builder(Context context) { public Builder(Context context) {
this.context = Assertions.checkNotNull(context); this.context = Assertions.checkNotNull(context);
vastLoadTimeoutMs = C.TIME_UNSET; vastLoadTimeoutMs = TIMEOUT_UNSET;
mediaLoadTimeoutMs = TIMEOUT_UNSET;
} }
/** /**
...@@ -113,13 +115,26 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -113,13 +115,26 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
* @return This builder, for convenience. * @return This builder, for convenience.
* @see AdsRequest#setVastLoadTimeout(float) * @see AdsRequest#setVastLoadTimeout(float)
*/ */
public Builder setVastLoadTimeoutMs(long vastLoadTimeoutMs) { public Builder setVastLoadTimeoutMs(int vastLoadTimeoutMs) {
Assertions.checkArgument(vastLoadTimeoutMs >= 0); Assertions.checkArgument(vastLoadTimeoutMs >= 0);
this.vastLoadTimeoutMs = vastLoadTimeoutMs; this.vastLoadTimeoutMs = vastLoadTimeoutMs;
return this; return this;
} }
/** /**
* Sets the ad media load timeout, in milliseconds.
*
* @param mediaLoadTimeoutMs The ad media load timeout, in milliseconds.
* @return This builder, for convenience.
* @see AdsRenderingSettings#setLoadVideoTimeout(int)
*/
public Builder setMediaLoadTimeoutMs(int mediaLoadTimeoutMs) {
Assertions.checkArgument(mediaLoadTimeoutMs >= 0);
this.mediaLoadTimeoutMs = mediaLoadTimeoutMs;
return this;
}
/**
* Returns a new {@link ImaAdsLoader} for the specified ad tag. * Returns a new {@link ImaAdsLoader} for the specified ad tag.
* *
* @param adTagUri The URI of a compatible ad tag to load. See * @param adTagUri The URI of a compatible ad tag to load. See
...@@ -128,7 +143,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -128,7 +143,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
* @return The new {@link ImaAdsLoader}. * @return The new {@link ImaAdsLoader}.
*/ */
public ImaAdsLoader buildForAdTag(Uri adTagUri) { public ImaAdsLoader buildForAdTag(Uri adTagUri) {
return new ImaAdsLoader(context, adTagUri, imaSdkSettings, null, vastLoadTimeoutMs); return new ImaAdsLoader(
context, adTagUri, imaSdkSettings, null, vastLoadTimeoutMs, mediaLoadTimeoutMs);
} }
/** /**
...@@ -139,7 +155,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -139,7 +155,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
* @return The new {@link ImaAdsLoader}. * @return The new {@link ImaAdsLoader}.
*/ */
public ImaAdsLoader buildForAdsResponse(String adsResponse) { public ImaAdsLoader buildForAdsResponse(String adsResponse) {
return new ImaAdsLoader(context, null, imaSdkSettings, adsResponse, vastLoadTimeoutMs); return new ImaAdsLoader(
context, null, imaSdkSettings, adsResponse, vastLoadTimeoutMs, mediaLoadTimeoutMs);
} }
} }
...@@ -174,6 +191,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -174,6 +191,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
private static final String FOCUS_SKIP_BUTTON_WORKAROUND_JS = "javascript:" private static final String FOCUS_SKIP_BUTTON_WORKAROUND_JS = "javascript:"
+ "try{ document.getElementsByClassName(\"videoAdUiSkipButton\")[0].focus(); } catch (e) {}"; + "try{ document.getElementsByClassName(\"videoAdUiSkipButton\")[0].focus(); } catch (e) {}";
private static final int TIMEOUT_UNSET = -1;
/** The state of ad playback. */ /** The state of ad playback. */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({IMA_AD_STATE_NONE, IMA_AD_STATE_PLAYING, IMA_AD_STATE_PAUSED}) @IntDef({IMA_AD_STATE_NONE, IMA_AD_STATE_PLAYING, IMA_AD_STATE_PAUSED})
...@@ -193,7 +212,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -193,7 +212,8 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
private final @Nullable Uri adTagUri; private final @Nullable Uri adTagUri;
private final @Nullable String adsResponse; private final @Nullable String adsResponse;
private final long vastLoadTimeoutMs; private final int vastLoadTimeoutMs;
private final int mediaLoadTimeoutMs;
private final Timeline.Period period; private final Timeline.Period period;
private final List<VideoAdPlayerCallback> adCallbacks; private final List<VideoAdPlayerCallback> adCallbacks;
private final ImaSdkFactory imaSdkFactory; private final ImaSdkFactory imaSdkFactory;
...@@ -282,7 +302,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -282,7 +302,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
* more information. * more information.
*/ */
public ImaAdsLoader(Context context, Uri adTagUri) { public ImaAdsLoader(Context context, Uri adTagUri) {
this(context, adTagUri, null, null, C.TIME_UNSET); this(
context,
adTagUri,
/* imaSdkSettings= */ null,
/* adsResponse= */ null,
/* vastLoadTimeoutMs= */ TIMEOUT_UNSET,
/* mediaLoadTimeoutMs= */ TIMEOUT_UNSET);
} }
/** /**
...@@ -298,7 +324,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -298,7 +324,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
*/ */
@Deprecated @Deprecated
public ImaAdsLoader(Context context, Uri adTagUri, ImaSdkSettings imaSdkSettings) { public ImaAdsLoader(Context context, Uri adTagUri, ImaSdkSettings imaSdkSettings) {
this(context, adTagUri, imaSdkSettings, null, C.TIME_UNSET); this(
context,
adTagUri,
imaSdkSettings,
/* adsResponse= */ null,
/* vastLoadTimeoutMs= */ TIMEOUT_UNSET,
/* mediaLoadTimeoutMs= */ TIMEOUT_UNSET);
} }
private ImaAdsLoader( private ImaAdsLoader(
...@@ -306,11 +338,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -306,11 +338,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
@Nullable Uri adTagUri, @Nullable Uri adTagUri,
@Nullable ImaSdkSettings imaSdkSettings, @Nullable ImaSdkSettings imaSdkSettings,
@Nullable String adsResponse, @Nullable String adsResponse,
long vastLoadTimeoutMs) { int vastLoadTimeoutMs,
int mediaLoadTimeoutMs) {
Assertions.checkArgument(adTagUri != null || adsResponse != null); Assertions.checkArgument(adTagUri != null || adsResponse != null);
this.adTagUri = adTagUri; this.adTagUri = adTagUri;
this.adsResponse = adsResponse; this.adsResponse = adsResponse;
this.vastLoadTimeoutMs = vastLoadTimeoutMs; this.vastLoadTimeoutMs = vastLoadTimeoutMs;
this.mediaLoadTimeoutMs = mediaLoadTimeoutMs;
period = new Timeline.Period(); period = new Timeline.Period();
adCallbacks = new ArrayList<>(1); adCallbacks = new ArrayList<>(1);
imaSdkFactory = ImaSdkFactory.getInstance(); imaSdkFactory = ImaSdkFactory.getInstance();
...@@ -361,7 +395,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -361,7 +395,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
} else /* adsResponse != null */ { } else /* adsResponse != null */ {
request.setAdsResponse(adsResponse); request.setAdsResponse(adsResponse);
} }
if (vastLoadTimeoutMs != C.TIME_UNSET) { if (vastLoadTimeoutMs != TIMEOUT_UNSET) {
request.setVastLoadTimeout(vastLoadTimeoutMs); request.setVastLoadTimeout(vastLoadTimeoutMs);
} }
request.setAdDisplayContainer(adDisplayContainer); request.setAdDisplayContainer(adDisplayContainer);
...@@ -796,6 +830,9 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A ...@@ -796,6 +830,9 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A
AdsRenderingSettings adsRenderingSettings = imaSdkFactory.createAdsRenderingSettings(); AdsRenderingSettings adsRenderingSettings = imaSdkFactory.createAdsRenderingSettings();
adsRenderingSettings.setEnablePreloading(ENABLE_PRELOADING); adsRenderingSettings.setEnablePreloading(ENABLE_PRELOADING);
adsRenderingSettings.setMimeTypes(supportedMimeTypes); adsRenderingSettings.setMimeTypes(supportedMimeTypes);
if (mediaLoadTimeoutMs != TIMEOUT_UNSET) {
adsRenderingSettings.setLoadVideoTimeout(mediaLoadTimeoutMs);
}
// Set up the ad playback state, skipping ads based on the start position as required. // Set up the ad playback state, skipping ads based on the start position as required.
long[] adGroupTimesUs = getAdGroupTimesUs(adsManager.getAdCuePoints()); long[] adGroupTimesUs = getAdGroupTimesUs(adsManager.getAdCuePoints());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment