From b007cbf2b488bd851f2af0e9d7642a60453ed606 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Tue, 30 Oct 2018 02:19:08 -0700 Subject: [PATCH] Let apps specify whether to focus skip button on ATV Issue: #5019 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219267048 --- RELEASENOTES.md | 3 +++ .../exoplayer2/ext/ima/ImaAdsLoader.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index bf734489b9..16b65aa09a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -26,6 +26,9 @@ ([#4532](https://github.com/google/ExoPlayer/issues/4532)). * Suppress spurious "references unknown class member" shrinking warning ([#4890](https://github.com/google/ExoPlayer/issues/4890)). +* IMA extension: + * Let apps specify whether to focus the skip button on ATV + ([#5019](https://github.com/google/ExoPlayer/issues/5019)). * Fix issue where a `NullPointerException` is thrown when removing an unprepared media source from a `ConcatenatingMediaSource` with the `useLazyPreparation` option enabled ([#4986](https://github.com/google/ExoPlayer/issues/4986)). 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 95a3a588b4..cc621c6218 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 @@ -93,6 +93,7 @@ public final class ImaAdsLoader private @Nullable AdEventListener adEventListener; private int vastLoadTimeoutMs; private int mediaLoadTimeoutMs; + private boolean focusSkipButtonWhenAvailable; private ImaFactory imaFactory; /** @@ -104,6 +105,7 @@ public final class ImaAdsLoader this.context = Assertions.checkNotNull(context); vastLoadTimeoutMs = TIMEOUT_UNSET; mediaLoadTimeoutMs = TIMEOUT_UNSET; + focusSkipButtonWhenAvailable = true; imaFactory = new DefaultImaFactory(); } @@ -159,6 +161,20 @@ public final class ImaAdsLoader return this; } + /** + * Sets whether to focus the skip button (when available) on Android TV devices. The default + * setting is {@code true}. + * + * @param focusSkipButtonWhenAvailable Whether to focus the skip button (when available) on + * Android TV devices. + * @return This builder, for convenience. + * @see AdsRenderingSettings#setFocusSkipButtonWhenAvailable(boolean) + */ + public Builder setFocusSkipButtonWhenAvailable(boolean focusSkipButtonWhenAvailable) { + this.focusSkipButtonWhenAvailable = focusSkipButtonWhenAvailable; + return this; + } + // @VisibleForTesting /* package */ Builder setImaFactory(ImaFactory imaFactory) { this.imaFactory = Assertions.checkNotNull(imaFactory); @@ -181,6 +197,7 @@ public final class ImaAdsLoader null, vastLoadTimeoutMs, mediaLoadTimeoutMs, + focusSkipButtonWhenAvailable, adEventListener, imaFactory); } @@ -200,6 +217,7 @@ public final class ImaAdsLoader adsResponse, vastLoadTimeoutMs, mediaLoadTimeoutMs, + focusSkipButtonWhenAvailable, adEventListener, imaFactory); } @@ -252,6 +270,7 @@ public final class ImaAdsLoader private final @Nullable String adsResponse; private final int vastLoadTimeoutMs; private final int mediaLoadTimeoutMs; + private final boolean focusSkipButtonWhenAvailable; private final @Nullable AdEventListener adEventListener; private final ImaFactory imaFactory; private final Timeline.Period period; @@ -338,6 +357,7 @@ public final class ImaAdsLoader /* adsResponse= */ null, /* vastLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaLoadTimeoutMs= */ TIMEOUT_UNSET, + /* focusSkipButtonWhenAvailable= */ true, /* adEventListener= */ null, /* imaFactory= */ new DefaultImaFactory()); } @@ -362,6 +382,7 @@ public final class ImaAdsLoader /* adsResponse= */ null, /* vastLoadTimeoutMs= */ TIMEOUT_UNSET, /* mediaLoadTimeoutMs= */ TIMEOUT_UNSET, + /* focusSkipButtonWhenAvailable= */ true, /* adEventListener= */ null, /* imaFactory= */ new DefaultImaFactory()); } @@ -373,6 +394,7 @@ public final class ImaAdsLoader @Nullable String adsResponse, int vastLoadTimeoutMs, int mediaLoadTimeoutMs, + boolean focusSkipButtonWhenAvailable, @Nullable AdEventListener adEventListener, ImaFactory imaFactory) { Assertions.checkArgument(adTagUri != null || adsResponse != null); @@ -380,6 +402,7 @@ public final class ImaAdsLoader this.adsResponse = adsResponse; this.vastLoadTimeoutMs = vastLoadTimeoutMs; this.mediaLoadTimeoutMs = mediaLoadTimeoutMs; + this.focusSkipButtonWhenAvailable = focusSkipButtonWhenAvailable; this.adEventListener = adEventListener; this.imaFactory = imaFactory; if (imaSdkSettings == null) { @@ -926,6 +949,7 @@ public final class ImaAdsLoader if (mediaLoadTimeoutMs != TIMEOUT_UNSET) { adsRenderingSettings.setLoadVideoTimeout(mediaLoadTimeoutMs); } + adsRenderingSettings.setFocusSkipButtonWhenAvailable(focusSkipButtonWhenAvailable); // Set up the ad playback state, skipping ads based on the start position as required. long[] adGroupTimesUs = getAdGroupTimesUs(adsManager.getAdCuePoints());