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

use*_*885 8 audio 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>
Run Code Online (Sandbox Code Playgroud)

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

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

Jat*_*tin 24

你在哪里呼叫停止只是按以下顺序执行以下操作:

 n.pause()
 n.currentTime = 0
 n.play()    
Run Code Online (Sandbox Code Playgroud)