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; ...@@ -661,6 +661,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
maskingPeriodIndex = getCurrentPeriodIndex(); maskingPeriodIndex = getCurrentPeriodIndex();
maskingWindowPositionMs = getCurrentPosition(); maskingWindowPositionMs = getCurrentPosition();
} }
// Also reset period-based PlaybackInfo positions if resetting the state.
resetPosition = resetPosition || resetState;
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
resetPosition resetPosition
? playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window) ? playbackInfo.getDummyFirstMediaPeriodId(shuffleModeEnabled, window)
......
...@@ -436,12 +436,6 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -436,12 +436,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
private void prepareInternal(MediaSource mediaSource, boolean resetPosition, boolean resetState) { private void prepareInternal(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
pendingPrepareCount++; 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( resetInternal(
/* resetRenderers= */ false, /* releaseMediaSource= */ true, resetPosition, resetState); /* resetRenderers= */ false, /* releaseMediaSource= */ true, resetPosition, resetState);
loadControl.onPrepared(); loadControl.onPrepared();
...@@ -864,11 +858,23 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -864,11 +858,23 @@ import java.util.concurrent.atomic.AtomicBoolean;
} }
} }
enabledRenderers = new Renderer[0]; enabledRenderers = new Renderer[0];
queue.clear(/* keepFrontPeriodUid= */ !resetPosition);
setIsLoading(false);
if (resetPosition) { if (resetPosition) {
pendingInitialSeekPosition = null; 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) { if (resetState) {
queue.setTimeline(Timeline.EMPTY); queue.setTimeline(Timeline.EMPTY);
for (PendingMessageInfo pendingMessageInfo : pendingMessages) { 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