【发布时间】:2012-11-06 01:46:54
【问题描述】:
见标题。我正在尝试每 300 毫秒连续播放 4 次音频文件。但是,剪辑超过 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
【问题讨论】:
-
-在运行 .play() 之前运行 .stop() 有效吗?- 从那以后我实际上读过一些文档 - 看起来没有 .stop()。但正如一些人所建议的那样,暂停然后将时间设置回 0 应该会产生相同的效果。
-
另外,仅供参考,您的 doctype 指定的 html 版本甚至不支持音频标签。将其更改为