From 60555e2c4b6d74f1276ae30b6524174ac8ee2365 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 20 Nov 2017 08:42:34 -0800 Subject: [PATCH] Improve robustness of ImaAdsLoader Remove an assertion that there was a call to pause content between two content -> ad transitions. Also, only use the player position for resuming an ad on reattaching if the player is currently playing an ad, in case IMA pauses content before the player actually transitions to an ad. Issue: #3430 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176365842 --- RELEASENOTES.md | 3 +++ .../com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b645cc81a0..13218f073f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -53,6 +53,9 @@ ([#3303](https://github.com/google/ExoPlayer/issues/3303)). * Ignore seeks if an ad is playing ([#3309](https://github.com/google/ExoPlayer/issues/3309)). + * Improve robustness of `ImaAdsLoader` in case content is not paused between + content to ad transitions + ([#3430](https://github.com/google/ExoPlayer/issues/3430)). * UI: * Allow specifying a `Drawable` for the `TimeBar` scrubber ([#3337](https://github.com/google/ExoPlayer/issues/3337)). 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 0b11a97f84..5b61db0264 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 @@ -260,7 +260,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A @Override public void detachPlayer() { if (adsManager != null && imaPausedContent) { - adPlaybackState.setAdResumePositionUs(C.msToUs(player.getCurrentPosition())); + adPlaybackState.setAdResumePositionUs(playingAd ? C.msToUs(player.getCurrentPosition()) : 0); adsManager.pause(); } lastAdProgress = getAdProgress(); @@ -628,7 +628,6 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A if (!wasPlayingAd && playingAd) { int adGroupIndex = player.getCurrentAdGroupIndex(); // IMA hasn't sent CONTENT_PAUSE_REQUESTED yet, so fake the content position. - Assertions.checkState(fakeContentProgressElapsedRealtimeMs == C.TIME_UNSET); fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime(); fakeContentProgressOffsetMs = C.usToMs(adPlaybackState.adGroupTimesUs[adGroupIndex]); if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {