javascript 如何在页面加载时播放声音片段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3362426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I play a sound clip on page load?
提问by nectar
how can I play a sound clip on page load?Is there any javascript or jquery to do that?I am creating my page in php.
如何在页面加载时播放声音片段?是否有任何 javascript 或 jquery 可以做到这一点?我正在用 php 创建我的页面。
回答by Jim W.
Through simple HTML.
通过简单的 HTML。
<object>
<param name="autostart" value="true">
<param name="src" value="sound.mp3">
<param name="autoplay" value="true">
<param name="controller" value="true">
<embed src="sound.mp3" controller="true" autoplay="true" autostart="True" type="audio/mp3" />
</object>
回答by CheeseConQueso
you can pull this off with straight html
你可以用直接的 html 来解决这个问题
http://www.webreference.com/js/column20/bgsound.html
http://www.webreference.com/js/column20/bgsound.html
or
或者
http://www.htmlcodetutorial.com/sounds/_BGSOUND.html
http://www.htmlcodetutorial.com/sounds/_BGSOUND.html
I think wav, mid, and mp3 are supported
我认为支持 wav、mid 和 mp3
回答by Karel Petranek
You can also combine the answers from premiso and CheeseConQueso with HTML5 audio tag: https://developer.mozilla.org/en/using_audio_and_video_in_firefox
您还可以将 premiso 和 CheeseConQueso 的答案与 HTML5 音频标签结合起来:https: //developer.mozilla.org/en/using_audio_and_video_in_firefox
回答by loncemon
The question was actually about how to do it in javascript.
问题实际上是关于如何在 javascript 中做到这一点。
var aClip = new Audio (path_to_file or URL);
aClip.play();

