random background music

S

Scott-ASC

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.
 
P

pcx99

Scott-ASC said:
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>');
 
J

Joseph Taylor

If you're going to make a website sing and dance, why not go all the
way and create it in Flash? Please note that this is not a
recommendation, but rather, a rhetorical question.
 
S

Scott-ASC

Thanks much...just what I wanted. I noticed you had Houston Chronicle
comics on your site. Houston, TX (well, actually Katy) native here.
Scott-ASC said:
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>');
 
P

pcx99

Scott-ASC said:
Thanks much...just what I wanted. I noticed you had Houston Chronicle
comics on your site. Houston, TX (well, actually Katy) native here.


Woodlands, but even if I were in Alaksa I'd still use the Houston
Chronicle comics, they're the best mainstream comic site on the net
today :)

Glad I could help you with your project!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top