PDA

View Full Version : How to Delay Random Music Player Script?


JudyEF
01-30-2003, 11:20 PM
I am using a random music player script and would like to delay the music playing upon page loading. Is there a way to use setTimeout with this script? The script code follows:

var numasf = 4
var name=navigator.appName

day = new Date()
seed = day.getTime()
ran = parseInt(((seed - (parseInt(seed/1000,10) * 1000))/10)/100*numasf + 1,10)

if (ran == (1))
asf=("GeorgeWinston-GreatPumpkinWaltz-1.asf")
if (ran == (2))
asf=("GeorgeWinston-ACharlieBrownChristmas-2.asf")
if (ran == (3))
asf=("GeorgeWinston-EightFiveFive-1.asf")
if (ran == (4))
asf=("ChickCoreaTheGreatPumpkinWaltz-1.asf")


document.write('<BGSOUND SRC="http://www.geocities.com/wellhands/' + asf + '" WIDTH=0 HEIGHT=2 AUTOSTART=TRUE LOOP=1>')

if (name=="Netscape")
document.write('<EMBED SRC="http://www.geocities.com/wellhands/' + asf + '" WIDTH=0 HEIGHT=2 AUTOSTART=TRUE>')

document.write('background music is <TT>' + asf + '</TT>')

-----------------------------------------------------

And one more question: Is there a way to make this random script a little less random, so that it will definitely NOT play the same song that was just played upon page reload/refresh?

Any help is greatly appreciated....

joeframbach
01-31-2003, 12:00 PM
function playSong()
{
var numasf = 4
var name=navigator.appName

ran=Math.floor(Math.random()*4)
//i'm sorry i forget the syntax

asf=["GeorgeWinston-GreatPumpkinWaltz-1.asf"
,"GeorgeWinston-ACharlieBrownChristmas-2.asf"
,"GeorgeWinston-EightFiveFive-1.asf"
,"ChickCoreaTheGreatPumpkinWaltz-1.asf"]


document.write('<BGSOUND SRC="http://www.geocities.com/wellhands/' + asf[ran] + '" WIDTH=0 HEIGHT=2 AUTOSTART=TRUE LOOP=1>')

if (name=="Netscape")
document.write('<EMBED SRC="http://www.geocities.com/wellhands/' + asf[ran] + '" WIDTH=0 HEIGHT=2 AUTOSTART=TRUE>')

document.write('background music is <TT>' + asf[ran] + '</TT>')
}

setTimeout("playSong()",5000)

JudyEF
01-31-2003, 03:51 PM
Thanks for your help, Joe. I'll give your script a whirl and let you know how it works out. Thanks again!

JudyEF
01-31-2003, 06:04 PM
Thanks for your time and effort with the script, Joe, although I couldn't get it to work. I fooled with it a bit but still no luck. If anyone can help with just getting the setTimeout function to work so the songs don't play immediately, that would be greatly appreciated. :rolleyes: