By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

random background music

P: n/a
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.

Dec 1 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Dec 1 '06 #2

P: n/a
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.

Dec 1 '06 #3

P: n/a
Thanks much...just what I wanted. I noticed you had Houston Chronicle
comics on your site. Houston, TX (well, actually Katy) native here.

pcx99 wrote:
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
Dec 1 '06 #4

P: n/a
Scott-ASC wrote:
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!

Dec 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.