473,765 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2521
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.lengt h;
var randomPick = Math.floor(Math .random()*numbe rOfFiles);
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.lengt h;
var randomPick = Math.floor(Math .random()*numbe rOfFiles);
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
9607
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 restarting)" when going to the other pages. Can anyone give me some insight as to how this can be done? Appreciate any help offered. TIA Peter
4
3799
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. The game uses the FMOD sound library to play an MP3 as background music. I got slightly bored of listening to the same song over and over and realised it would be much nicer if the game could pick an MP3 at random from a folder...
4
3401
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" AUTOSTART="true" LOOP="true" VOLUME=100% WIDTH=400 HEIGHT=100 CONSOLE="MYCONSOLE"><!-- -->
1
453
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 actions to take place, presumably I'll have to use the common dialog controls for open and save but I've got no idea how to pass these values to and from the streamwriter/readers file get and file put methods, could anyone point me in the right...
4
3885
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 music. The music plays okay until the viewer clicks to cause some JavaScript code to execute. When the JavaScript code runs it stops the music even though the coding is just used to resize pictures and divs on the page (viz, it is not supposed...
21
62856
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: url(graphics/header-salmoninbucket.jpg); background-repeat: no-repeat; background-color: #B6C7B6; } When you print, however, this doesn't appear.
3
7961
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
4412
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 the native PlaySound function but the results were the same. Any ideas how to have a background music and a button sound without using DirectSound? Can you provide me some snippets?
17
12886
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 page the music stops. How can I achieve this. any ideas !!!!! Regards Muddasir Hussain
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9833
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.