diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java index 3878ba20369..c63228315f0 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java @@ -3030,6 +3030,11 @@ private static PositionUpdateForPlaylistChange resolvePositionForPlaylistChange( } } + long periodPositionDeltaUs = checkPlayingPeriodPositionChanged(timeline, playbackInfo, period.windowIndex); + if (periodPositionDeltaUs > 0) { + periodPositionUs = periodPositionUs - periodPositionDeltaUs; + } + return new PositionUpdateForPlaylistChange( newPeriodId, periodPositionUs, @@ -3039,6 +3044,22 @@ private static PositionUpdateForPlaylistChange resolvePositionForPlaylistChange( setTargetLiveOffset); } + private static long checkPlayingPeriodPositionChanged(Timeline timeline, PlaybackInfo playbackInfo, int currentWindowIndex) { + long periodPositionDeltaUs = C.TIME_UNSET; + if (!playbackInfo.timeline.isEmpty() && !timeline.isEmpty() && !playbackInfo.periodId.isAd()) { + Timeline.Window newWindow = timeline.getWindow(currentWindowIndex, new Timeline.Window()); + Timeline.Window oldWindow = playbackInfo.timeline.getWindow(currentWindowIndex, new Timeline.Window()); + if (oldWindow.isDynamic && ! newWindow.isDynamic) { + Timeline.Period newPeriod = timeline.getPeriodByUid(playbackInfo.periodId.periodUid, new Timeline.Period()); + int windowIndex = newPeriod.windowIndex; + Pair oldPositionZero = playbackInfo.timeline.getPeriodPosition(oldWindow, new Timeline.Period(), windowIndex, 0); + Pair newPositionZero = timeline.getPeriodPosition(newWindow, new Timeline.Period(), windowIndex, 0); + periodPositionDeltaUs = oldPositionZero.second - newPositionZero.second; + } + } + return periodPositionDeltaUs; + } + private static boolean isIgnorableServerSideAdInsertionPeriodChange( boolean isUsingPlaceholderPeriod, MediaPeriodId oldPeriodId,