473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

random background music

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
4 2501
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter | last post by:
I've embedded a midi file as background sound in my "index.html" which links to other pages on the site and I want the the same background sound to play on all pages "without interruption (and...
4
by: SoulSniper | last post by:
Hi, I have been stuck on this for a few days now and have given up trawling through pages and pages of google results.. I'm just putting the finishing touches to a small game I've written....
4
by: jassan | last post by:
Does anybody know how to modify the following so that it does a random play from the .rpm file? <!-- --><embed SRC="http://your-url.rpm" type="audio/x-pn-realaudio-plugin" CONTROLS="Control"...
1
by: Steven Smith | last post by:
Hi guys When working with random access files .NET creates, saves to and loads from a default location (i.e. the solutions bin directory) how can I specify at runtime where I want these...
4
by: Doug van Vianen | last post by:
Hi, I am using Visual Basic 6 to generate web pages that can be used by the members of our seniors' computer club to create e-cards that include their own pictures. I wish to include background...
21
by: tradmusic.com | last post by:
Hi, We have the following in our stylesheet, which acts as a page header: #homepageheader { left: 0px; top: 0px; right: 0px; height: 183px; background-image:...
3
by: paodzy | last post by:
how to import a background music in vb6.if the form is load then the music will start to play.can you please post the code for this.please help me....
2
by: ventsislav | last post by:
I want to have a background music to my simple app and a buton which plays another sound, but when I press the button the sound from it interrupts the background sound. I tried with SoundPlayer and...
17
by: Muddasir | last post by:
Hi everyone. How can I play music in background while user can browse through my website. Uptill now I have created a music player which plays audio tracks but as soon as users jumps to another...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.