Fix handling of postrolls preloading

The IMA SDK now preloads postrolls which is great as we no longer need
to rely on detecting buffering at the end of the stream to trigger
playing postrolls.

Add in the required logic to detect the period transition to playing
the postroll.

Issue: #7518
PiperOrigin-RevId: 317610682
This commit is contained in:
andrewlewis 2020-06-22 09:42:35 +01:00 committed by Andrew Lewis
parent 6d9a1ed639
commit 0ff917ad35
2 changed files with 16 additions and 6 deletions

View File

@ -229,6 +229,8 @@
on seeking to another position
([#7492](https://github.com/google/ExoPlayer/issues/7492)).
* Fix incorrect rounding of ad cue points.
* Fix handling of postrolls preloading
([#7518](https://github.com/google/ExoPlayer/issues/7518)).
### 2.11.5 (2020-06-05) ###

View File

@ -1098,6 +1098,13 @@ public final class ImaAdsLoader implements Player.EventListener, AdsLoader {
}
if (!sentContentComplete && !wasPlayingAd && playingAd && imaAdState == IMA_AD_STATE_NONE) {
int adGroupIndex = player.getCurrentAdGroupIndex();
if (adPlaybackState.adGroupTimesUs[adGroupIndex] == C.TIME_END_OF_SOURCE) {
adsLoader.contentComplete();
if (DEBUG) {
Log.d(TAG, "adsLoader.contentComplete from period transition");
}
sentContentComplete = true;
} else {
// IMA hasn't called playAd yet, so fake the content position.
fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
fakeContentProgressOffsetMs = C.usToMs(adPlaybackState.adGroupTimesUs[adGroupIndex]);
@ -1106,6 +1113,7 @@ public final class ImaAdsLoader implements Player.EventListener, AdsLoader {
}
}
}
}
private void resumeContentInternal() {
if (imaAdInfo != null) {
@ -1221,7 +1229,7 @@ public final class ImaAdsLoader implements Player.EventListener, AdsLoader {
&& positionMs + THRESHOLD_END_OF_CONTENT_MS >= contentDurationMs) {
adsLoader.contentComplete();
if (DEBUG) {
Log.d(TAG, "adsLoader.contentComplete");
Log.d(TAG, "adsLoader.contentComplete from content position check");
}
sentContentComplete = true;
}