fix: playback starts from seeked position instead of beginning
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user