Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random music (midi)

Status
Not open for further replies.

bennyf118

Programmer
Nov 16, 2000
6
US
I am trying to make a page choose a random music selection and then play it...

I use this as the random function...

function get_random()
{
var ranNum= Math.round(Math.random()*10);
return ranNum;
}

I use this to select the music being played...

function getsong()
{
var songnum=get_random();

var song=new Array(10)
song[0]="james_bond_theme.mid";
song[1]="her_majestys.mid";
song[2]="tomorrow_never_dies.mid";
song[3]="for_your_eyes_only.mid";
song[4]="goldeneye.mid";
song[5]="you_only_live_twice.mid";
song[6]="a_view_to_a_kill.mid";
song[7]="goldfinger.mid";
song[8]="live_n_let_die.mid";
song[9]="spy_who_loved_me.mid";

return(song[songnum]);

Finally, I try to play it using

<EMBED SRC=getsong() AUTOSTART=&quot;TRUE&quot; HIDDEN=&quot;TRUE&quot; LOOP=&quot;TRUE&quot;> <NOEMBED>
<BGSOUND ID=&quot;sound&quot; LOOP=&quot;INFINITE&quot;> </NOEMBED>

However, this doesn't play any music at all. I've tried putting quotes around the getsong(), but that doesn't work either. Can someone please quickly check through my code and see if they find any errors?
 
Instead of assigning a script to post a name to the <EMBED>, have the script assign the <EMBED> tag itself....

var song=new Array(10)
song[0]=&quot;<EMBED SRC='james_bond_theme.mid' AUTOSTART='true' HIDDEN='true'>&quot;; Jonathan Hannan
Computer Repair, Webdesign
HTML, CGI, PERL, JavaScript, XML
 
and then what would you do with the html part? just delete it? BTW, also, are you sure this works, or is it just a stab in the dark? thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top