From de915bd6a100f7fdea9d2b88b0f5f8814f90fbab Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 6 Sep 2019 10:00:53 +0100 Subject: [PATCH] Handle potential timeline updates that switch from content to ad. We currently don't test if an ad needs to be played in case we are already playing content. This is to prevent recreating the current content period when an ad is marked as skipped. We prefer playing until the designated ad group position and appending another piece of content. This is less likely to cause visible discontinuities in case the ad group position is at a key frame boundary. However, this means we currently miss updates that require us to play an ad after a timeline update. PiperOrigin-RevId: 267553459 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 8beb7d781e..1478a1b2bf 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -1326,9 +1326,16 @@ import java.util.concurrent.atomic.AtomicBoolean; timeline, timeline.getPeriodByUid(newPeriodUid, period).windowIndex, C.TIME_UNSET); newContentPositionUs = defaultPosition.second; newPeriodId = queue.resolveMediaPeriodIdForAds(defaultPosition.first, newContentPositionUs); - } else if (newPeriodId.isAd()) { - // Recheck if the current ad still needs to be played. - newPeriodId = queue.resolveMediaPeriodIdForAds(newPeriodId.periodUid, newContentPositionUs); + } else { + // Recheck if the current ad still needs to be played or if we need to start playing an ad. + newPeriodId = + queue.resolveMediaPeriodIdForAds(playbackInfo.periodId.periodUid, newContentPositionUs); + if (!playbackInfo.periodId.isAd() && !newPeriodId.isAd()) { + // Drop update if we keep playing the same content (MediaPeriod.periodUid are identical) and + // only MediaPeriodId.nextAdGroupIndex may have changed. This postpones a potential + // discontinuity until we reach the former next ad group position. + newPeriodId = playbackInfo.periodId; + } } if (playbackInfo.periodId.equals(newPeriodId) && oldContentPositionUs == newContentPositionUs) {