Best way to integrate sound into website

Go To StackoverFlow.com

5

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.

2009-06-16 08:49
by Alec Smart
Just make sure you give users the option to disable this feature. Many would find it annoying - RichardOD 2009-06-16 08:59
as RichardOD says, make sure people can disable it. People don't expect websites to make sounds, and are often very annoyed by it (I know I am) - Pim Jager 2009-06-16 09:22


6

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

2009-06-16 08:52
by Rad
swf's are definitely the way to go - Blindy 2009-06-16 09:25


2

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.

2009-06-16 08:57
by gonzohunter


0

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.

2009-06-16 08:59
by Claes Mogren


0

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.

2009-06-16 09:01
by Leonard Ehrenfried
What browsers support HTML5 currently - Patrick McDonald 2009-06-16 09:26
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 - Leonard Ehrenfried 2009-06-16 11:19


0

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.

2009-06-16 09:01
by merkuro


0

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

2009-06-16 09:19
by Alastair Montgomery


0

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

Please make a clearly visible mute button too! :)

2009-06-16 09:24
by John Smith


0

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/

2009-06-16 09:39
by Lodewijk


0

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.

2010-01-22 06:30
by Volomike