admin 管理员组文章数量: 1086019
How can play sound using JavaScript only, without using the <audio>
tag?
I'm using:
var audio = {};
audio["walk"] = new Audio();
audio["walk"].src = "Scr/dave.wma"
audio["walk"].load()
setTimeout('audio["walk"].play()',1000);
But it doesn’t play?
How can play sound using JavaScript only, without using the <audio>
tag?
I'm using:
var audio = {};
audio["walk"] = new Audio();
audio["walk"].src = "Scr/dave.wma"
audio["walk"].load()
setTimeout('audio["walk"].play()',1000);
But it doesn’t play?
Share Improve this question edited Aug 19, 2011 at 18:32 Paul D. Waite 99k57 gold badges203 silver badges271 bronze badges asked Aug 19, 2011 at 1:20 Moh97Moh97 732 silver badges8 bronze badges2 Answers
Reset to default 6No browsers support the Windows Media Audio format.
You should be using the Ogg Vorbis, MP3 and Wave formats.
Here is a table of audio format support in the five major browsers:
Ogg Vorbis MP3 Wave
Firefox * *
Safari * *
Chrome * *
Opera * *
Internet Explorer * *
Please note: the above table may be outdated.
In addition, as alex has stated, the statements are asynchronous and do not wait for the audio file to have loaded. You will need to listen for the load
event and call play
within the event handler.
As Delan says, no browser supports WMA.
However, your code still has a problem.
You need to wait until the audio
has loaded.
var audio = {};
audio["walk"] = new Audio();
audio["walk"].src = "Scr/dave.wma"
audio["walk"].addEventListener('load', function() {
audio["walk"].play();
});
本文标签: htmlHow can I play sound in JavaScript without using the ltaudiogt tagStack Overflow
版权声明:本文标题:html - How can I play sound in JavaScript, without using the <audio> tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744091801a2532171.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论