From 7cd85f0bb16b5ebf6d7ce6983c77588a7e90734a Mon Sep 17 00:00:00 2001 From: daniel-c-harvey Date: Sun, 7 Jun 2026 16:55:31 -0400 Subject: [PATCH] fix: convert absolute pause position to buffer-relative on resume after seek-beyond-buffer --- DeepDrftPublic/Interop/audio/AudioPlayer.ts | 6 ++++-- DeepDrftPublic/Interop/audio/PlaybackScheduler.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DeepDrftPublic/Interop/audio/AudioPlayer.ts b/DeepDrftPublic/Interop/audio/AudioPlayer.ts index cc0a755..49cf414 100644 --- a/DeepDrftPublic/Interop/audio/AudioPlayer.ts +++ b/DeepDrftPublic/Interop/audio/AudioPlayer.ts @@ -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 }; diff --git a/DeepDrftPublic/Interop/audio/PlaybackScheduler.ts b/DeepDrftPublic/Interop/audio/PlaybackScheduler.ts index d4bfef3..0f3b587 100644 --- a/DeepDrftPublic/Interop/audio/PlaybackScheduler.ts +++ b/DeepDrftPublic/Interop/audio/PlaybackScheduler.ts @@ -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;