Scott-ASC wrote:
I'm looking for some code that will allow me to have a random wav file
played every time someone refreshes my home page. I've found some that
will allow 5 different wavs (and it wasn't scalable), but I've got 100+
wavs that I'd like to use so I need some code that can scale. Any help
would be appreciated.
I know it's not the answer you're looking for, but I am simply compelled
to point out that introducing background sound into a web-site is one of
the top design mistakes when creating a web-site. What sounds good to
you may be offensive to others (the leave your site and never come back
kind of offensive), and many people browse the web with the TV, Radio,
or other music/information source running and a website with sound ruins
that experience.
Now the answer you're looking for...
//add as many file names into the Array as you want
var fileNames = new Array("add.wav", "as.wav", "many.wav",
"filenames.wav", "here.wave", "as.wav", "you.wav", "want.mp3");
//You won't need to modify the next 3 lines
var numberOfFiles = fileNames.length;
var randomPick = Math.floor(Math.random()*numberOfFiles);
var filename = fileNames[randomPick];
//You'll probably want to modify the following line to get the music in
//your web page the way you want it. Just note that "filename" has the
//randomly picked filename from the array above.
document.write('<embed src="'+filename+'" autostart=false loop=false>');
---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
$FA