Click to See Complete Forum and Search --> : random sound


vinsa
02-26-2003, 01:22 PM
Hello,
first sorry for my english. I need
from javascript for random sound.
He must select random sound file from some.
Example:
sound1.mp3
sound2.mp3
sound3.mp3
sound4.mp3
sound5.mp3
sound6.mp3
sound7.mp3
sound8.mp3
When I click of the link, the javascript must
select random sound of these up there.
Thank you previous!
My e-mail: iivanov2@abv.bg
All the best!

dabush
02-26-2003, 02:16 PM
i think this works but i didnt try it yet.


<html>
<head>
<script language=JavaScript>
<!--
function randomSound()
{
var sound_array = new Array();
sound_array[0] = "http://domain.com/sound1.mp3";
sound_array[1] = "http://domain.com/sound2.mp3";
sound_array[2] = "http://domain.com/sound3.mp3";
sound_array[3] = "http://domain.com/sound4.mp3";
sound_array[4] = "http://domain.com/sound5.mp3";
sound_array[5] = "http://domain.com/sound6.mp3";
sound_array[6] = "http://domain.com/sound7.mp3";
sound_array[7] = "http://domain.com/sound8.mp3";
var rndm_sound = Math.round(Math.random()*sound_array.length);
open(sound_array[rndm_sound],"mysound","");
}
// -->
</script>
</head>
<body>
<a href="javascript:randomSound();">Play a Random Sound</a>
</body>
</html>

pyro
02-26-2003, 04:54 PM
This shows how to do three. More can be added very easily:

http://forums.webdeveloper.com/showthread.php?s=&threadid=4093