所以我有一些按钮,人们可以按下这些按钮来收听音频文件。当然,音频文件不能“重叠”,因为那会一团糟。这可行,但现在我希望其中一个文件在网站加载时自动播放,仍然保持这样一个事实,即每当我按下另一个按钮时它就会停止。
这是我到目前为止所得到的:
头:
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"false\" loop=\"true\" />";
}
</script>
body :
<span id="dummy"></span>
<p style="text-align:center;">
<a href="#" onclick="playSound('Sound1.mp3');">
<img class="alignnone" width="128" img src="Img1.png" ></a>
<a href="#" onclick="playSound('Sound2.mp3');">
<img class="alignnone" width="128" img src="Img2.png" ></a>
<a href="#" onclick="playSound('Sound3.mp3');">
<img class="alignnone" width="128" img src="Img3.png" ></a>
</p>
最佳答案
试试这个 jquery 解决方案:
http://archive.plugins.jquery.com/project/sound_plugin
我在 react 时间测试中成功地使用了它,我必须在每次测试之前播放声音。
关于Javascript自动播放声音文件,单击其中一个按钮时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718345/