From 958c6d668075c92c1dadc66c47d813f02d32bd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 17 Nov 2025 17:21:10 +0100 Subject: [PATCH] fix: playback starts from seeked position instead of beginning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed critical bug where playback always started from 0:00 regardless of seek position or pause state. Root cause: - play() method called stop() which reset pauseTime to 0 - Then it checked isPaused (now false) and pauseTime (now 0) - Result: always played from beginning Solution: - Calculate offset BEFORE calling stop() - Preserve the paused position or start offset - Then stop and recreate source node with correct offset Now playback correctly starts from: - Seeked position (waveform click or timeline slider) - Paused position (when resuming after pause) - Specified start offset (when provided) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/audio/player.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/audio/player.ts b/lib/audio/player.ts index 45787b9..65f4e98 100644 --- a/lib/audio/player.ts +++ b/lib/audio/player.ts @@ -40,6 +40,9 @@ export class AudioPlayer { // Resume audio context if needed await resumeAudioContext(); + // Calculate start offset BEFORE stopping (since stop() resets pauseTime) + const offset = this.isPaused ? this.pauseTime : startOffset; + // Stop any existing playback this.stop(); @@ -48,8 +51,7 @@ export class AudioPlayer { this.sourceNode.buffer = this.audioBuffer; this.sourceNode.connect(this.gainNode); - // Calculate start offset - const offset = this.isPaused ? this.pauseTime : startOffset; + // Set start time this.startTime = this.audioContext.currentTime - offset; // Start playback