I am looking to integrate sound into a website. Basically a chat website where users will hear a sound when a new message arrives. What do you think is the best way to integrate sound?
Thank you for your time.
A small swf with the sound controlled by javascript would the the way to go in terms of being cross platform and cross browser.
I would go with option #2. But, with a word of caution when integrating any sound into a web site, people often find it annoying, when a sound comes out of the blue.
As Conrad said, use javascript and swf. You can also take a look at what other people use. One example that I like is the Campfire chat. It works in all browsers and OS:es that I've tried it with.
The most elegant solution would be to use the upcoming HTML5 <audio>
tag. You can script this from JavaScript. Support for this is poor, however.
As as said by others, the alternative would be a Flash solution.
I would recommend using the <audio>
tag where possible and Flash as fallback content.
I personally don't like websites that need JavaScript activated to accomplish something in Flash (eg. youtube), because generally speaking I have deactivated JavaScript. Therefore I would suggest to only use Flash. However this is a personal thing. Most users probably don't mind.
Personally I don't like background music or sounds on websites. Reminds me of the bad old days were every site had a background MIDI file on it.
At least have the option to switch it off :)
Please make a clearly visible mute button too! :)
This is a very nice API that uses flash and javascript to make embedding sound in your webpages easy as something very easy: http://www.schillmania.com/projects/soundmanager2/
Setting aside the ethics of whether to make a sound play in a web page automatically...
I've got this working with XHTML 1.0 Strict in FF 3.x+, Opera 9.x+, IE6+, but not in Chrome (3.0.195.38) or Safari (4.0.4). So, I can't figure out how to get Webkit to accept it. Note this likely will not pass XHTML validation. And also note that my doctype stuff starts off like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Anyway, although the following code doesn't work yet in Webkit browsers, it works in other browsers:
<bgsound src="http://example.com/sound.wav" loop="0" />
<audio src="http://example.com/sound.wav" autoplay loop="false" />
If anyone know how to get this working in Webkit browsers, I'd like to know how.