Commit 28c7cb37 by tonihei Committed by Oliver Woodman

Reset period position when resetState=True.

This is more in line with "forgetting all previous state" as documented for
resetState=True. Also only apply the current position as initial seek position
in this case.
PiperOrigin-RevId: 236623630
parent 7a1b8a95
......@@ -661,6 +661,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
maskingPeriodIndex = getCurrentPeriodIndex();
maskingWindowPositionMs = getCurrentPosition();
}
// Also reset period-based PlaybackInfo positions if resetting the state.
resetPosition = resetPosition || resetState;
MediaPeriodId mediaPeriodId =
resetPosition
? playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window)
......
......@@ -436,12 +436,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void prepareInternal(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
pendingPrepareCount++;
if (!resetPosition && pendingInitialSeekPosition == null && !playbackInfo.timeline.isEmpty()) {
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
long windowPositionUs = playbackInfo.positionUs + period.getPositionInWindowUs();
pendingInitialSeekPosition =
new SeekPosition(Timeline.EMPTY, period.windowIndex, windowPositionUs);
}
resetInternal(
/* resetRenderers= */ false, /* releaseMediaSource= */ true, resetPosition, resetState);
loadControl.onPrepared();
......@@ -864,11 +858,23 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
}
enabledRenderers = new Renderer[0];
queue.clear(/* keepFrontPeriodUid= */ !resetPosition);
setIsLoading(false);
if (resetPosition) {
pendingInitialSeekPosition = null;
} else if (resetState) {
// When resetting the state, also reset the period-based PlaybackInfo position and convert
// existing position to initial seek instead.
resetPosition = true;
if (pendingInitialSeekPosition == null && !playbackInfo.timeline.isEmpty()) {
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
long windowPositionUs = playbackInfo.positionUs + period.getPositionInWindowUs();
pendingInitialSeekPosition =
new SeekPosition(Timeline.EMPTY, period.windowIndex, windowPositionUs);
}
}
queue.clear(/* keepFrontPeriodUid= */ !resetPosition);
setIsLoading(false);
if (resetState) {
queue.setTimeline(Timeline.EMPTY);
for (PendingMessageInfo pendingMessageInfo : pendingMessages) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment