<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Random mp3 Player</title>
<style type="text/css">
body {
text-align:center;
}
#music {
height:1px;
width:1px;
line-height:0px;
font-size:0;
position:absolute;
left:0;
top:0;
}
</style>
<script type="text/javascript">
<!--
function PlayIt(mp3){
nummp3 = 5 //this needs to be the number of songs you have
day = new Date()
z = day.getTime()
y = (z - (parseInt(z/1000,10) * 1000))/10
x = parseInt(y/100*nummp3,10) + 1
//to add more songs follow the format below, add as many as you like
if (x == (1)){
mp3=("http://www.xxxxxx.com/MusicVid/chevy.mp3")
}
if (x == (2)){
mp3=("http://www.xxxxxx.com/MusicVid/sugar.mp3")
}
if (x == (3)){
mp3=("http://www.xxxxxx.com/MusicVid/tree.mp3")
}
if (x == (4)){
mp3=("http://www.xxxxxx.com/MusicVid/grandma.mp3")
}
if (x == (5)){
mp3=("http://www.xxxxxx.com/MusicVid/bells.mp3")
}
document.getElementById('music').innerHTML='<object width="1" height="1" '
+'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '
+'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
+'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
+'<param name="url" value="'+mp3+'">'
+'<param name="uiMode" value="full">'
+'<param name="autoStart" value="true">'
+'<param name="loop" value="true">'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'showcontrols="true" uimode="full" width="1" height="1" '
+'src="'+mp3+'" autostart="true" loop="true">'
+'<\/object>';
}
window.onload=PlayIt;
//-->
</script>
</head>
</html>
Need help with random background music code
Started by RocketFoot, Dec 04 2009 02:17 PM
1 reply to this topic
#1
Posted 04 December 2009 - 02:17 PM
I have this code running on a contest page on one of my sites. it works by playing a random song on start or refresh, but I need it to loop randomly through all 5 songs. What am I missing in the code?
#2
Posted 22 June 2011 - 02:44 PM
sorry for the nooby question, but what does the "http://www.w3.org/TR/html4/loose.dtd"> mean?
i know such website, but why is this url in the code?
i know such website, but why is this url in the code?
I develop free html shoutbox for invisionmodding registered members!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users





Contributor










