[英]Javascript autoplay soundfile, stop when one of the buttons is clicked
So I've got some buttons, which people can press to hear audio files. 所以我有一些按钮,人们可以按这些按钮来收听音频文件。 Of course, the audio files can't "overlap" because that would be a mess.
当然,音频文件不能“重叠”,因为那样会很混乱。 This works, but now I want one of the files to play automatically when the website loads, still maintaining the fact that it will stop whenever I press another button.
这可行,但是现在我希望其中一个文件在网站加载时自动播放,但仍然保持这样的事实,只要我按另一个按钮,它就会停止。
This is what I've got so far: 到目前为止,这是我得到的:
Head: 头:
<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>
Try this jquery solution: 试试这个jQuery解决方案:
http://archive.plugins.jquery.com/project/sound_plugin http://archive.plugins.jquery.com/project/sound_plugin
I used this successfully in a reaction time test where I had to play a sound just before each test. 我在反应时间测试中成功使用了此功能,在每次测试前都必须播放声音。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.