katspaugh/wavesurfer.js

RangeError: Failed to execute 'start' on 'AudioBufferSourceNode'

1ndoryu opened this issue · 1 comments

Bug description

With version 7.7.8 of wavesurfer.js, I’m experiencing a recurring issue with playback. When clicking near the start of the waveform, an intermittent error appears about 2 out of 10 times:

Uncaught (in promise) RangeError: Failed to execute 'start' on 'AudioBufferSourceNode': The offset provided (-0.0444035) is less than the minimum bound (0).

Additionally, after this error occurs, the following error sometimes appears when trying to stop the audio:

Uncaught InvalidStateError: Failed to execute 'stop' on 'AudioScheduledSourceNode': cannot call stop without calling start first.

The only way to resolve the issue is by refreshing the page and trying again. This seems to happen more frequently when clicking near the beginning of the waveform.

Environment

  • Browser: Chrome
  • wavesurfer.js version: 7.7.8

Minimal code snippet

The issue occurs in the _play() and _pause() methods in wavesurfer.js:

// In _play():
let e = this.playedDuration * this._playbackRate;
e >= this.duration && (e = 0, this.playedDuration = 0),
this.bufferNode.start(this.audioContext.currentTime, e);

// In _pause():
null === (t = this.bufferNode) || void 0 === t || t.stop();

Expected result

Audio playback should start and stop without errors or negative offsets, even when clicking near the start of the waveform.

Obtained result

Intermittent RangeError due to a negative offset and occasional InvalidStateError from stop being called without start. The error can only be resolved by reloading the page.

"It's not complicated to replicate the error; sometimes it happens, sometimes it doesn't. You just need to click at the beginning of the waveform within the first six lines, and that will be enough for it to fail."

https://2upra.com/sample/classic-soul-sample/

image