tags:

views:

275

answers:

9

Hello,

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?

  1. Javascript to play the sound
  2. Javascript to call a flash swf which plays the sound
  3. Any other method I cant think of?

Thank you for your time.

+6  A: 

A small swf with the sound controlled by javascript would the the way to go in terms of being cross platform and cross browser.

Conrad
swf's are definitely the way to go.
Blindy
+2  A: 

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.

gonzohunter
A: 

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.

Claes Mogren
A: 

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.

Lenni
What browsers support HTML5 currently?
Patrick McDonald
IE 8, FF3.5, Chrome and Safari 4 all support *some* HTML5. I think only Safari and FF do the audio tags at the moment.
Lenni
A: 

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.

merkuro
A: 

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 :)

Alastair
A: 

3 Use Flash. It's widely supported and it works better than Java applets.

Please make a clearly visible mute button too! :)

abababa22
Oops, didn't mean to yell. I wish that SO used a less error prone formatting system like bbcode etc.
abababa22
A: 

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/

Lodewijk
A: 

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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.

Volomike