mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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:
parent
7a1b8a9585
commit
28c7cb3716
2 changed files with 16 additions and 8 deletions
|
|
@ -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;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue