使用html5 / javascript播放声音 [英] playing a sound using html5/javascript
本文介绍了使用html5 / javascript播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题:如果某个数字超过100,我希望用户听到某种声音。
My Problem: I would like a user to hear a sound of some sort if a number is over 100.
If (x > 100) { play sound }
我该怎么走?关于这个使用html5 / javascript。是否可以在没有内嵌小视频剪辑的情况下播放声音。到目前为止,我见过的唯一的东西就是嵌入页面中的那些小快速播放器: http:// www.w3schools.com/html/html_sounds.asp
How would I go about this using html5/javascript. Is it possible to play sound without having an inline little video clip. The only stuff I've seen thus far has those little quicktime players embedded within the page: http://www.w3schools.com/html/html_sounds.asp
希望有更好的解决方案吗?谢谢
Hopefully there's a better solution? Thanks
推荐答案
var foo = document.createElement('audio');
foo.src = 'https://dl.dropbox.com/u/8090976/Matrix%20Ring.aiff';
if (x > 100)
{
document.getElementById('foo').play();
}
演示: http://jsfiddle.net/mattball/ZcRt9/
更多阅读: http://html5doctor.com/native-audio-in-the-browser
这篇关于使用html5 / javascript播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文