Playing a sound in an AJAX chat
I am using the Audio class to play a sound in an AJAX chat when there's a new message. My code:
if ( ! $.browser.msie || ( $.browser.msie && parseFloat(jQuery.browser.version) >= 9 ) )
{
//var notif = new Audio('http://cycle1500.com/sounds/infbego.wav');
var notif = new Audio('/media/sounds/drip.wav');
notif.play();
}
- I am checking the version of IE because only 9 seems to support HTML5 audio. Is there a better way to do it?
var notif = new Audio('http://c开发者_Go百科ycle1500.com/sounds/infbego.wav');
worksvar notif = new Audio('/media/sounds/drip.wav');
doesn't work Why not?- Where can I find documentation on how to construct the Audio class?
You can use HTML5
<audio>
tag in you application, this will be supported in recent browser version and to support older version you can create fallback.
Clear and beautiful documentation is here.Have a look .
http://html5doctor.com/native-audio-in-the-browser/
精彩评论