Skip to content

fix(WebAudio): prevent position reset when seeking to duration#4283

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-seek-jump-to-start
Open

fix(WebAudio): prevent position reset when seeking to duration#4283
Copilot wants to merge 4 commits intomainfrom
copilot/fix-seek-jump-to-start

Conversation

Copy link

Copilot AI commented Feb 3, 2026

  • Analyze the issue: When seeking near the end of an audio track, playback jumps to the beginning
  • Explore the codebase: Found the issue in both WebAudioPlayer and MediaElement backends
  • Identify root causes:
    • WebAudio: The condition currentPos >= this.duration was resetting to 0 when position equaled duration
    • MediaElement: When media.ended is true and play(start, end) is called, the seek might not complete before play is invoked, causing the browser to restart from the beginning
  • Implement fixes:
    • WebAudio: Changed >= to > so only positions strictly past the duration are reset
    • MediaElement: Added wait for 'seeked' event before calling play when media is ended
  • Add unit tests for both scenarios
  • Run linting and tests - all 320 tests pass
  • Run security check - no vulnerabilities found
Original prompt

This section details on the original issue you should resolve

<issue_title>When seeking near the end of an audio track, it always jumps back to the beginning and starts playback from the start position.</issue_title>
<issue_description><!--
BEFORE SUBMITTING:

  • Please search in the existing issues to make sure this issue hasn't been reported already
  • If you're not 100% certain if it's a bug in wavesurfer or your own code, please DO NOT create an issue and ask in the Q&A first: https://github.com/katspaugh/wavesurfer.js/discussions/categories/q-a
  • The sections below are required to fill out. Bug reports without a minimal code snippet and other required information will be immediately closed.
    -->

Bug description

For example, with a 33-second audio clip, if playback reaches around the 31-second mark and you attempt to seek, it always automatically jumps back to the beginning and starts playing from the start. Even using the ws.play(start, end) method no longer works as expected.
https://github.com/user-attachments/assets/da3debc0-e9de-4788-8978-08abd47d8679

Environment

  • Browser: Chrome
  • Version: 7.10.1

Minimal code snippet

Expected result

Obtained result

Screenshots

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 3, 2026 15:47
Co-authored-by: katspaugh <381895+katspaugh@users.noreply.github.com>
Co-authored-by: katspaugh <381895+katspaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix seek functionality jumping back to start position fix(WebAudio): prevent position reset when seeking to duration Feb 3, 2026
Copilot AI requested a review from katspaugh February 3, 2026 15:52
@katspaugh katspaugh marked this pull request as ready for review February 3, 2026 16:03
@katspaugh
Copy link
Owner

@copilot thanks for fixing it for WebAudio but the original issue didn't say specifically WebAudio, so I would assume they had the bug with the default media element playback.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 3, 2026

Deploying wavesurfer-js with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e7c1b4
Status: ✅  Deploy successful!
Preview URL: https://1e6ae945.wavesurfer-js.pages.dev
Branch Preview URL: https://copilot-fix-seek-jump-to-sta.wavesurfer-js.pages.dev

View logs

Co-authored-by: katspaugh <381895+katspaugh@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 3, 2026

@copilot thanks for fixing it for WebAudio but the original issue didn't say specifically WebAudio, so I would assume they had the bug with the default media element playback.

Added a fix for the default MediaElement backend in commit 4e7c1b4. When the media is ended and play(start, end) is called, we now wait for the 'seeked' event to fire before calling play(). This prevents the browser from restarting from the beginning when the seek hasn't completed yet.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@katspaugh
Copy link
Owner

@AsherAla can you test if this branch solves the issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When seeking near the end of an audio track, it always jumps back to the beginning and starts playback from the start position.

2 participants