mpen
mpen

Reputation: 282865

What's the best way to play a sound from my website?

I know it's generally frowned upon, but in this case I think it might actually be helpful. I want to play a little "ding" sound when a new item is posted on my site. I'll leave the option to turn it off of course.

Now should I do this with JavaScript? Would jQuery be helpful? Or should I use Flash? Looking for something that is widely compatible with different browsers. A link to a code sample or library would be helpful.

Upvotes: 2

Views: 587

Answers (3)

David Hellsing
David Hellsing

Reputation: 108500

You should probably look into the <audio> tag in HTML5 and then degrade it gracefully to flash/embed. Fore more advanced audio controls, FF4 beta has implemented an entire audio API, docs are here:

https://wiki.mozilla.org/Audio_Data_API

This is probably the direction audio on the web will take, but for wider support you should gracefully degrade it to a flash/embed solution.

Today, I think FF3.5+, Safari3+ and Chrome3+ supports the <audio> tag, but you should double-check codecs for Safari.

Upvotes: 1

GrandmasterB
GrandmasterB

Reputation: 3455

Caveat...I'm not sure if this still works in modern browsers. But what I did in years past was simply write out an embed tag with an audio file as a source, ala:

document.write( '<embed src="some.wav"></embed>');

and the sound would be played when that was added to the page. It was actually used in a chat system and seemed to work ok. That being said, I have no doubt there's more modern, flash or ajaxy ways of doing this. But if you cant find another solution, this might work for ya.

Upvotes: 1

Marko
Marko

Reputation: 72222

Yep, use the jQuery Media plugin - it does exactly that :)

Upvotes: 2

Related Questions