我有一个按钮,当按下时它应该播放短暂的声音。它在第一次按下并播放声音时起作用。下一次和所有其他时间它不起作用(直到我重新加载页面,然后再次工作)。我的代码如下:HTML5音频按钮 - 第一次按下,然后停止工作
我试着添加audio.stop(); before audio.play();希望它能解决它,但它使它不工作。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML5</title>
</head>
<body>
<audio>
<source src="buzzer.mp3" type="audio/mpeg">
</audio>
<input type="submit" id="buttonPlaySound" value="Play Sound">
<script>
var audio = document.getElementsByTagName("audio")[0];
buttonPlaySound.onclick = function() {
audio.play();
};
</script>
</body>
</html>
您正在使用的浏览器上面的解决方案是否行得通呢? – Neel 2013-02-13 04:38:09
Mac OS X上的Safari 6.0.2 10.8.2 – user1822824 2013-02-13 04:39:04
您是先试用这个吗? http://stackoverflow.com/questions/9335577/html5-audio-sound-only-plays-once – 2013-02-13 04:39:07