HTML5音频:如何快速停止和重新启动剪辑?

标题.我试图连续4次播放音频文件,每300毫秒.但是,剪辑长度超过300毫秒,因此它会在剪辑完成播放之前忽略新的播放请求.我正在寻找一种方法来停止并重新启动剪辑每300毫秒.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <Meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
    <audio id="note0440"><source src="0440.a4.wav" type="audio/wav"></audio>
    <script type="text/javascript">
        function playNote (loop) {
            var n = document.getElementById("note0440")
            if (loop > 4)
                return
            n.volume = 0.05
            // n.currentTime = 0
            n.pause()
            n.play()
            setTimeout("playNote("+(loop + 1)+")",300)
        }
    </script>
    <div style="margin:50px"><button onclick="playNote(1)">Play Note</button></div>
</body>
</html>

这不起作用.无论是否使用n.currentTime = 0,它都不会停止并重新启动.

如果你需要一个WAV文件,这是一个WAV文件http://popstrip.com/misc/0440.a4.wav

解决方法

你在哪里呼叫停止只需按以下顺序执行以下操作:
n.pause()
 n.currentTime = 0
 n.play()

相关文章

HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码