We have a facebook like chat, and we want to be able to play a sound when someone receives a new message. What is the best way to go about this? If needed it is ok if we use HTML5 for this, but preferrably a cross-browser solution.
Asked
Active
Viewed 273 times
0
-
1possible duplicate of [Cross-platform, cross-browser way to play sound from Javascript?](http://stackoverflow.com/questions/187098/cross-platform-cross-browser-way-to-play-sound-from-javascript) – Jakub Jan 19 '12 at 14:32
-
there are a ton of already asked questions pertaining to this subject, look at the **Related** column on the right hand of the screen. – Jakub Jan 19 '12 at 14:33
-
Eish, when typing the question I didn't see any matching questions, but I do now on the right-hand side. tnx – Richard Jan 19 '12 at 14:37
2 Answers
1
This is easy with HTML5
<audio id="mySoundClip">
<source src="audio/beep.mp3"></source>
<source src="audio/beep.ogg"></source>
Your browser isn't invited for super fun audio time.
</audio>
and the jQuery bit
var audio = $("#mySoundClip")[0];
audio.play();
This will provide support for Firefox 3.5+, Chrome 3+, Opera 10.5+, Safari 4+, & IE 9+

kamui
- 3,339
- 3
- 26
- 44
0
For a cross browser solution, you might want to look at MediaElement.js. You can create an <audio>
element on your page, hide it, and call .play
on it whenever you want the sound to play.

Alex Turpin
- 46,743
- 23
- 113
- 145