From 0c9e92136aecd3f2568420c0cc1df23e4b007678 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Wed, 28 Oct 2020 10:04:20 +0000 Subject: [PATCH] Fix skipping behavior in ad pods ImaAdsLoader notified onEnded whenever an ad finished playing, but when an ad is skipped in an ad pod we'd receive a playAd call before the player discontinuity for skipping to the next ad. Fix this behavior by checking that IMA's playing ad matches the player's playing ad before notifying onEnded. #minor-release PiperOrigin-RevId: 339424910 --- RELEASENOTES.md | 2 ++ .../android/exoplayer2/ext/ima/ImaAdsLoader.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 31f21e4c57..387fb247a8 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -13,6 +13,8 @@ ([#7344](https://github.com/google/ExoPlayer/issues/7344)). * Improve handling of ad tags with unsupported VPAID ads ([#7832](https://github.com/google/ExoPlayer/issues/7832)). + * Fix a bug that caused multiple ads in an ad pod to be skipped when one + ad in the ad pod was skipped. ### 2.12.1 (2020-10-23) ### 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 d619c1fe84..265ffe585b 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 @@ -1300,13 +1300,18 @@ public final class ImaAdsLoader if (adMediaInfo == null) { Log.w(TAG, "onEnded without ad media info"); } else { - for (int i = 0; i < adCallbacks.size(); i++) { - adCallbacks.get(i).onEnded(adMediaInfo); + @Nullable AdInfo adInfo = adInfoByAdMediaInfo.get(adMediaInfo); + if (playingAdIndexInAdGroup == C.INDEX_UNSET + || (adInfo != null && adInfo.adIndexInAdGroup < playingAdIndexInAdGroup)) { + for (int i = 0; i < adCallbacks.size(); i++) { + adCallbacks.get(i).onEnded(adMediaInfo); + } + if (configuration.debugModeEnabled) { + Log.d( + TAG, "VideoAdPlayerCallback.onEnded in onTimelineChanged/onPositionDiscontinuity"); + } } } - if (configuration.debugModeEnabled) { - Log.d(TAG, "VideoAdPlayerCallback.onEnded in onTimelineChanged/onPositionDiscontinuity"); - } } if (!sentContentComplete && !wasPlayingAd && playingAd && imaAdState == IMA_AD_STATE_NONE) { int adGroupIndex = player.getCurrentAdGroupIndex();