Hello.
When paused and resumed twice, the audio will start from the beginning.
audio.play()
...
audio.pause()
...
audio.play()
...
audio.pause()
...
audio.play() // issue occurs
I override the audio pause function in my project, and it's behavior meets my expectation. The only change is variable this._pauseAt
THREE.Audio.prototype.pause = function () {
if (this.hasPlaybackControl === false) {
console.warn('THREE.Audio: this Audio has no playback control.')
return
}
if (this.isPlaying === true) {
// this._pausedAt = ( this.context.currentTime - this._startedAt ) * this.playbackRate;
this._pausedAt = this.context.currentTime * this.playbackRate
this.source.stop()
this.source.onended = null
this.isPlaying = false
}
return this
}
Yes, I can confirm that the current implementation is buggy if you start/pause the audio more than once. Thanks for the fiddles!
However, your change is not 100% correct since it does not work if you pass in a delay when first calling play().
https://jsfiddle.net/vwbnoey6/
Notice how the audio starts at the wrong place after calling pause().
I think this is the correct change: https://jsfiddle.net/8gyfszbL/
@SUDOCS Can you please verify? The idea is to implement the line like so:
this._pausedAt += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
In this way, this._pausedAt should always point to the right position in the audio buffer. The usage of Math.max() ensures that the time value can't be negative. This could happen when using play() with a delay and immediately pause the audio.
@Mugen87 I have tried your method. Each time play/pause clicked, the audio starts from right position. Thank you a lot.馃榾
Most helpful comment
@Mugen87 I have tried your method. Each time
play/pauseclicked, the audio starts from right position. Thank you a lot.馃榾