views:

470

answers:

8

I have 6 sound files (1.wav 2.wav etc..) of which 3 different ones have to be heard each time the web page opens. The numbers are selected randomly. I have tried multiple "embeds" but only the last sound selected gets produced. I have also tried javascript routines that fiddle the bgsound attribute, however, I was not able to produce more than one sound at a time. The sounds are required to play either automatically on page open or they can be triggered by a click on a button or link, however, only one click is acceptable for the three sounds. Is there another way to do this? suggestions very welcome.

+2  A: 

I would use Flash if i'm trying to add sound into a webpage, you can embed a flash document with no width or height so it will be invisible but still play noise.

Cetra
How can you, using flash do what I need. Can i combine 3 separate sounds to play one after the other, randomly chosen?
+3  A: 

I've got a good idea: DON'T!

I hate web sites that play sounds without my telling them to. I use a multi-tabbed browser, and a multi-tasking operating system, and you don't have control of my computer, so don't assume you can play a sound without interfering with other things I'm doing.

Paul Tomblin
This is a serious application for audio sensory training. Your comment is rather abbrasive.
Web sites that play sounds are pretty abrasive too.You might want to note in your question that playing sounds is an important aspect of your application's functionality. Most sounds on the web are just annoying.
Kristopher Johnson
He asked "how" not "should I".
James
@Engram - if somebody asked you "how do I shoot you in the head", would you answer "how", or "should you"?
Paul Tomblin
I down voted you because there are many ways to say "This is how you do it but in my experience I would shy away from playing sounds without the user's permission" Your way of saying DON'T and giving an opinion does not help solve the problem.
Ron Skufca
@Ron, then please give me information on how to break into your house, including any weaknesses in your security system, where you hide your keys and when you're likely to not be home. Please note that if you don't give me the information before you say DON'T, I'll be voting you down.
Paul Tomblin
A: 

A browser will split page loading into multiple items and thus it's likely to load all sounds at once using multiple threads. I think what you're trying to accomplish is impossible.

diciu
+6  A: 

A simple Flash would do the trick better than anything else. However please consider that unless you develop your page for the Intranet application and the feature was specifically requested by the users it will most likely go against the best usability practices for web. Most users consider the pages which produce sounds to be very distractive and if the sound is produced on the page load the most likely will not be able to turn it off. If you want to embed some sound in your page you may allow the user to turn it on explicitely.

Ilya Kochetov
How can you, using flash do what I need. Can i combine 3 separate sounds to play one after the other, randomly chosen?
Of course. Using Flash for playing sounds is really easy. Selecting a random one is easy as well.
Ilya Kochetov
A: 

I know this is a bit exorbitant, but the number of combinations are not overly excessive. If you pre-blend the wav files into a series of files and just name them as follows

1_2_3, 1_2_3, 1_2_5, 1_2_6 
1_3_4, 1_3_5, 1_3_6
1_4_5, 1_4_6
2_3_4, 2_3_5, 2_3_6, 
2_4_5, 2_4_6,
2_5_6
3_4_5, 3_4_6,
3_5_6,
4_5_6

( fortunately not too many combinations )

and then as long as you do:

   $n = [ randomnumber , randomnumber , randomnumber ]; 
   $n = sort $n; 
   file = "$n[0]_$n[1]_$n[2].wav"

that should get it working.

Noted many people are opposed to sound and depending on what technique you use to play it it may/may not work for all, but that's probably a feature we should get browsers to enforce, because some people like being able to hear sounds ( shocking, but true ).

Kent Fredric
On your model assumes asceending numberes only, allowing all sequences there would be 6*5*4 combinations which = 120. My model allows duplicates too, so there would be 6*6*6 = 216 combinations. That is just too clumsy, however, its the only workable solution I have heard so far.
+1  A: 

If you're not against using a JavaScript framework to play a sound scriptaculous provides an API for playing sounds.

http://github.com/madrobby/scriptaculous/wikis/sound

Eric DeLabar
your solution shows how to play and stop a sound, it does not show how to play 2 or more souns one after the other.
A: 

Adding Sounds - HTML Lessons HTML MUSIC / MEDIA CODE - Sound http://html-lesson.blogspot.com/2008/06/music-media-code-sound.html

+2  A: 

Check out Sound Manager 2 an invisible flash movie that you can use to play sounds. It allows you to load and play multiple sounds.

To do what you wish to accomplish I would re-encode the wav files as mp3s (so that they download faster and Sound Manager can play them). Then use javascript to get sound manager to create the sounds and play them in a random order. You can listen to the onfinish event of each sound to start playing the next sound.

Karl