Click to See Complete Forum and Search --> : Background Music


jasonlim67
02-12-2003, 08:54 PM
Hello,

I would like to know, how can I make my website to have more than 1 background music(3). As example, when visitors visit my site, the first music will be played. But, when they click refresh, the second music will be played. When refresh is clicked again, the third music will be played.

Before this, I had came across a website with this feature. So, I would like to know how this thing is done.

Thank You.

pyro
02-12-2003, 10:12 PM
It sounds like you are looking for a random sound player? If so (ie. random is ok, rather than it actually playing sound 1, sound 2, sound 3) then this code should work for you.

<body>
<script language="javascript" type="text/javascript">
<!--hide

for (i=0; i<100; i++)
{
var x = Math.random()*3

var sound1="song1.mid"
var sound2="song2.mid"
var sound3="song3.mid"

if(x<=1)var sound=sound1
else if(x<=2)var sound=sound2
else var sound=sound3

document.write('<bgsound src='+'"'+sound+'"'+'loop="false">')

}
//END hide-->
</script>
</body>

jasonlim67
02-13-2003, 03:32 AM
Hello

No, I mean that the background songs will keep on changing. As example, when I go to www.xyz.com, the song1.mid will be played. But, when I go to www.xyz.com again, song2 will be played.


Go to this Malaysian site, and you will understand what I mean.
http://special.time.net.my/aidilfitri/

Thank You.

pyro
02-13-2003, 07:11 AM
Ok, I took a look at the site you pointed me to and from what it sounds like, they use some sort of random song generator, like the one I gave above... Did you try that? Each time you reload your page, it will randomly choose which of the songs you get.

jasonlim67
02-14-2003, 02:27 AM
Hello,

I have tried out the scripts which you have given to me. Quite good. Thank you for helping me.