-
Notifications
You must be signed in to change notification settings - Fork 24
Make seek work consistently before and after playback starts
#103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the seek() method to work correctly when called before audio decoding or playback has started, eliminating silent failures in early lifecycle states.
Key Changes:
- Added
_pendingSeekTimeproperty to queue seek requests before audio is ready - Modified
seek()to store pending seeks instead of failing silently - Updated
play()to apply any pending seek time before starting playback
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/audio/Audio.ts | Implements pending seek storage, updates seek() to handle early calls, and modifies play() to apply pending seeks |
| src/audio/tests/Audio.test.ts | Adds test coverage for seeking before play() is called and before audio is decoded |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| this._pauseTime = this._pendingSeekTime | ||
| this._pendingSeekTime = null | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending seek ignored when called after play but before decoding
When seek() is called after play() but before audio decoding completes, the seek time is stored in _pendingSeekTime but never applied. The decoded event listener only checks _pauseTime, not _pendingSeekTime. This means seeks requested during the decoding phase are silently dropped. The pending seek logic at lines 199-203 only handles seeks made before play() is called, not seeks made during the async decoding window.
Additional Locations (1)
| if (this._pendingSeekTime !== null) { | ||
| this._pauseTime = this._pendingSeekTime | ||
| this._pendingSeekTime = null | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending seek value not re-clamped when applied
When seek() is called before audio is loaded with a time exceeding the eventual duration, the value is stored in _pendingSeekTime without upper-bound clamping (since duration is unknown/zero). When this pending seek is applied in play(), _pauseTime is set directly without re-clamping to the now-known duration. The immediate seek path at line 361 re-clamps with Math.min(clampedTime, this.duration), but the pending seek application path doesn't. This causes source.start() to receive an offset beyond the buffer duration, resulting in immediate silent end of playback.
The
seek()method currently fails silently when called before audio is decoded or playback has started.This PR implements a fix for this issue:
_pendingSeekTime: number | nullprivate propertyseek()to accept and store seeks at any lifecycle stateplay()to apply pending seek before starting playbackNote
Improves
seek()reliability across lifecycle states._pendingSeekTimeto queue seeks made before decoding/initial playbackplay()to apply any pending seek before startingseek()to clamp safely (handles unknown duration) and to queue when not decoded; recreates source when playing, updates pause time when pausedplay()and before decodingWritten by Cursor Bugbot for commit 26a30f6. This will update automatically on new commits. Configure here.