Random Html Music

Mu online season 21 - grand opening

Elijah

Crystal Dev
Developer
Jul 21, 2004
1,806
18
265
Ok, well im creating a site and have background music, but rather being stuck with one song playing same everytime i hit the page, i want to be able to let it randomly pick one out of so many i upload.

So im just wondering what HTML code id have to use to make it randomly choose from a few mp3's i upload.

Please keep it as simple as possible, as the guides on it i found i couldnt fully understand so iv turned to the help of here i guess..

Now being told it cant be done in html, any help with writing a php script/java script to able me to do this would be appreciated.

/Tofas
 
Last edited:

LeoCrasher

Former Administrator
VIP
Mar 23, 2003
2,001
4
215
::1
Just made this for u in 2 secs Tofas, lemme no if you need nethin else ^^

Code:
<?PHP
//Random MP3 onload by LeoCrasher

//List of MP3 files you have in directory
  $mp3[1] = "Girls Aloud - Biology.mp3";
  $mp3[2] = "Black Eyed Peas - Dont Lie.mp3";
  $mp3[3] = "Gorillaz Dare.mp3";
  $mp3[4] = "test1.m3u";

//Random number selection.
  srand((double)microtime()*1000000);
  $ransel = rand(1,count($mp3));

?>

<html>
<embed src="<? echo $mp3[$ransel]; ?>" width="400" height="200" autostart="true">
</html>

EDIT:
Should you want to furthur play with the EMBED tag, see the following site (ignoring the javascript area):
http://digitalmedia.oreilly.com/2005/02/23/mp3_embed.html

/Leo
 
Last edited:

Elijah

Crystal Dev
Developer
Jul 21, 2004
1,806
18
265
LeoCrasher said:
Just made this for u in 2 secs Tofas, lemme no if you need nethin else ^^

Code:
<?PHP
//Random MP3 onload by LeoCrasher

//List of MP3 files you have in directory
  $mp3[1] = "Girls Aloud - Biology.mp3";
  $mp3[2] = "Black Eyed Peas - Dont Lie.mp3";
  $mp3[3] = "Gorillaz Dare.mp3";
  $mp3[4] = "test1.m3u";

//Random number selection.
  srand((double)microtime()*1000000);
  $ransel = rand(1,count($mp3));

?>

<html>
<embed src="<? echo $mp3[$ransel]; ?>" width="400" height="200" autostart="true">
</html>
EDIT:
Should you want to furthur play with the EMBED tag, see the following site (ignoring the javascript area):
http://digitalmedia.oreilly.com/2005/02/23/mp3_embed.html

/Leo

Thank you Leo for taking the time and doing that for me, i know it didnt take you long but i really do appreciate that you did take your time to do that for myself :eek:

/Tofas

- Ok, so basically i add this code to each page of my site, now everytime i click to a different part of my site the song starts/playing again, So 2 questions

1. Is it possible to keep the song playing which ever part of the site you go to, without it reloading the song? If so how?
2. After one songs played will it go to another or just loop the same song as thats the one randomy picked the first time?
 
Last edited:

Martyn

Smir.co.uk
Staff member
Administrator
Mar 24, 2003
4,095
4
1,006
410
Kent - UK
really wild guess. as i have no clue..

<embed src="<? echo $mp3[$ransel]; ?>" width="400" height="200" autostart="true">

add like repeat="true"

<embed src="<? echo $mp3[$ransel]; ?>" width="400" height="200" autostart="true" repeat="true">

just to see if it works. lol
 

LeoCrasher

Former Administrator
VIP
Mar 23, 2003
2,001
4
215
::1
1. Is it possible to keep the song playing which ever part of the site you go to, without it reloading the song? If so how?
--Not 'really'. However where theres a will theres a way. For example you could use an invisible frame (with the above code in) which remains static as the user browses the site (without the above code) in the other frame.

2. After one songs played will it go to another or just loop the same song as thats the one randomy picked the first time?
--Thats why I linked you to the EMBED page. Adding repeat="true" loops THE SAME SONG over and over. Obviously if you wish to loop a series of songs instead, you place the songs in a playlist as noted in my example as test1.m3u. To start songs randomly when a playlist is included, make multiple lists but with the same songs in a different order.

/Leo