Play sound when receiving a web chat message
How can I add simple sound when a message arrives in a w开发者_JAVA技巧eb chat session with jQuery?
I noticed that they do it on the chat at http://chat.stackoverflow.com and I want to emulate that in my own software.
jPlayer allows you to do this, and avoid Flash (with the HTML5 <audio>
tag).
Edit:
As drachenstern noted in the comments, SO Chat actually uses jPlayer. Some code from the chat page:
<div id="jplayer" style="position: absolute; top: 0px; left: 0px;">
<embed name="jqjp_flash_0" id="jqjp_flash_0" src=
"http://or.sstatic.net/chat/Jplayer.swf" width="0" height="0" bgcolor="#FFFFFF"
quality="high" flashvars="id=jplayer&fid=jqjp_flash_0&vol=80"
allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage=
"http://www.macromedia.com/go/getflashplayer" />
<div id="jqjp_force_0" style="text-indent: -9999px;">
0.7310569109395146
</div>
</div>
Have you considered using a jQuery Sound plugin that controls a Flash element?
This is a simple sound player, it uses flash to play the sounds, but DOES NOT provide a flash interface for any controls, everything is controlled via jQuery
$("#sound").sound({swf: url});
$("#sound").load(url);
$("#sound").play();
$("#sound").pause();
$("#sound").stop();
$("#sound").volume(0-100);
精彩评论