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
This commit is contained in:
tonihei 2019-03-04 11:30:06 +00:00 committed by Oliver Woodman
parent 7a1b8a9585
commit 28c7cb3716
2 changed files with 16 additions and 8 deletions

View file

@ -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)

View file

@ -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) {