From 2a685da4eb6dec725f737803d223ad9e5d27fa75 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 41748fa10d2..81a45c9c241 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -72,6 +72,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 0b11a97f844..5b61db0264a 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 void attachPlayer(ExoPlayer player, EventListener eventListener, ViewGrou @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 @@ private void updateImaStateForPlayerState() { 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) {