fix: convert absolute pause position to buffer-relative on resume after seek-beyond-buffer
This commit is contained in:
@@ -227,8 +227,10 @@ export class AudioPlayer {
|
||||
this.isPlaying = true;
|
||||
this.isPaused = false;
|
||||
|
||||
// Resume from pause position
|
||||
this.scheduler.playFromPosition(this.pausePosition);
|
||||
// Resume from pause position. pausePosition is absolute track time;
|
||||
// playFromPosition expects a buffer-relative position (excludes playbackOffset).
|
||||
const bufferRelativePosition = this.pausePosition - this.scheduler.getPlaybackOffset();
|
||||
this.scheduler.playFromPosition(Math.max(0, bufferRelativePosition));
|
||||
this.startProgressTracking();
|
||||
|
||||
return { success: true };
|
||||
|
||||
@@ -235,7 +235,9 @@ export class PlaybackScheduler {
|
||||
const position = this.getCurrentPosition();
|
||||
this.isActive_ = false; // Prevent handleSourceEnded from scheduling more
|
||||
this.stopAllSources();
|
||||
this.playbackAnchorPosition = position;
|
||||
// getCurrentPosition() returns absolute time (anchor + playbackOffset); the anchor
|
||||
// is buffer-relative, so strip the offset back out before storing it.
|
||||
this.playbackAnchorPosition = position - this.playbackOffset;
|
||||
this.playbackAnchorTime = 0;
|
||||
this.nextScheduleTime = 0;
|
||||
return position;
|
||||
|
||||
Reference in New Issue
Block a user