请看标题。我正在尝试连续播放一个音频文件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文件:http://popstrip.com/misc/0440.a4.wav