见标题.我试图连续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()