在AJAX聊天中播放声音

时间:2023-01-24 08:35:35

I am using the Audio class to play a sound in an AJAX chat when there's a new message. My code:

当有新消息时,我正在使用Audio类在AJAX聊天中播放声音。我的代码:

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();
}
  1. I am checking the version of IE because only 9 seems to support HTML5 audio. Is there a better way to do it?
  2. 我正在检查IE的版本,因为只有9似乎支持HTML5音频。有没有更好的方法呢?
  3. var notif = new Audio('http://cycle1500.com/sounds/infbego.wav'); works var notif = new Audio('/media/sounds/drip.wav'); doesn't work
    Why not?
  4. var notif = new Audio('http://cycle1500.com/sounds/infbego.wav'); works var notif = new Audio('/ media / sounds / drip.wav');什么不行?
  5. Where can I find documentation on how to construct the Audio class?
  6. 在哪里可以找到有关如何构建Audio类的文档?

1 个解决方案

#1


1  

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.

您可以在您的应用程序中使用HTML5

Clear and beautiful documentation is here.Have a look .
http://html5doctor.com/native-audio-in-the-browser/

清晰漂亮的文档在这里。看看。 http://html5doctor.com/native-audio-in-the-browser/

#1


1  

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.

您可以在您的应用程序中使用HTML5

Clear and beautiful documentation is here.Have a look .
http://html5doctor.com/native-audio-in-the-browser/

清晰漂亮的文档在这里。看看。 http://html5doctor.com/native-audio-in-the-browser/