当歌曲在 html 音频标签中重播时,如何消除间隙?

How can I remove the gap when the song replays in the html audio tag?

当我在 html5 音频元素上使用 'loop' 属性时,歌曲重播时似乎有间断。有没有简单的方法来消除这个差距?

代码:

<audio controls loop preload>
  <source src="http://www.phatdrumloops.com/audio/wav/ifineededs.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>

正在工作 fiddle 示例:

https://jsfiddle.net/rmwumaz7/

这实际上是音频标签的问题。但是,您可以尝试通过执行以下操作来尽量减少影响:

var audio = new Audio('http://www.phatdrumloops.com/audio/wav/ifineededs.wav')
audio.addEventListener('timeupdate', function(){
            var buffer = .1
            if(this.currentTime > this.duration - buffer){
                this.currentTime = 0
                this.play()
            }}, false);
 audio.play()

编辑:根据您的意见,我进行了更深入的研究。这是我发现的: https://github.com/Hivenfour/SeamlessLoop

这里的问题是,您需要以毫秒为单位提供正确的曲目长度(您要循环播放的曲目)

在此处查看 fiddle。 https://jsbin.com/simuvoduhi/edit?html,js,output