From d0dd33e5d339216326d8aa1e7c127b334b8c7ef1 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Wed, 10 Feb 2021 09:53:13 +0000 Subject: [PATCH] Add a method to focus the 'skip ad' button, if shown Issue: #8565 PiperOrigin-RevId: 356691251 --- RELEASENOTES.md | 3 +++ .../google/android/exoplayer2/ext/ima/AdTagLoader.java | 10 ++++++++++ .../android/exoplayer2/ext/ima/ImaAdsLoader.java | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 214b635a48b..3f9dffbe134 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -11,6 +11,9 @@ * Fix a bug where an assertion would fail if the player started to buffer an ad media period before the ad URI was known then an ad state update arrived that didn't set the ad URI. + * Add `ImaAdsLoader.focusSkipButton` to allow apps to request that the + skip button should receive UI focus, if shown + ([#8565](https://github.com/google/ExoPlayer/issues/8565)). * DRM: * Re-use the previous `DrmSessionManager` instance when playing a playlist (if possible) diff --git a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/AdTagLoader.java b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/AdTagLoader.java index 624a009bb7d..9908e4940cc 100644 --- a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/AdTagLoader.java +++ b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/AdTagLoader.java @@ -281,6 +281,16 @@ public void skipAd() { } } + /** + * Moves UI focus to the skip button (or other interactive elements), if currently shown. See + * {@link AdsManager#focus()}. + */ + public void focusSkipButton() { + if (adsManager != null) { + adsManager.focus(); + } + } + /** * Starts passing events from this instance (including any pending ad playback state) and * registers obstructions. 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 e2adbaf2d02..336a560042b 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 @@ -473,6 +473,16 @@ public void skipAd() { } } + /** + * Moves UI focus to the skip button (or other interactive elements), if currently shown. See + * {@link AdsManager#focus()}. + */ + public void focusSkipButton() { + if (currentAdTagLoader != null) { + currentAdTagLoader.focusSkipButton(); + } + } + // AdsLoader implementation. @Override