本文介绍了HTML5音频:如何快速停止并重新启动剪辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参阅称号。我试图播放音频文件连续4次,每次300毫秒。然而,剪辑是超过300ms的时间越长,因此它会忽略新戏请求,直到剪辑完成播放。我正在寻找一些方法来停止并重新启动剪辑每300毫秒。
See title. I am trying to play an audio file 4 times in a row, every 300 milliseconds. However, the clip is longer than 300ms, so it ignores new play requests until the clip is done playing. I'm looking for some way to stop and restart the clip every 300ms.
<!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
被使用。
This does not work. It does not stop and restart, whether or not n.currentTime = 0
is used.
下面是一个WAV文件,如果你需要一个用来测试:
Here's a WAV file if you need one for testing: http://popstrip.com/misc/0440.a4.wav
推荐答案
在任何你叫站仅做顺序如下 -
where ever you calling stop just do the following in the order of -
n.pause()
n.currentTime = 0
n.play()
这篇关于HTML5音频:如何快速停止并重新启动剪辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!