MyBB Community Forums

Full Version: Music Player Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I added this code to my website (I know...forced music sucks! But this is just for a 12 Days of Christmas specials we are running at work, so it is OK! LOL) Problem is that it should play a random song, one after another for an endless loop but what it does is play a random song on page refresh and then it keeps playing the same song over and over. I need it to automatically choose a new song each time and play it (without refreshing the page) Can anyone help me tweak the code to play random endlessly?

<html>
<head>
<title>Random BG Music Player</title>
</head>
<body>

<script type="text/javascript">

var musicSource = [
    "http://www.bigmacktrucks.com/music/1.mp3",
    "http://www.bigmacktrucks.com/music/2.mp3",
    "http://www.bigmacktrucks.com/music/3.mp3",
    "http://www.bigmacktrucks.com/music/4.mp3",
    "http://www.bigmacktrucks.com/music/5.mp3",
    "http://www.bigmacktrucks.com/music/6.mp3",
    "http://www.bigmacktrucks.com/music/7.mp3",
    "http://www.bigmacktrucks.com/music/8.mp3"
];

var rand = Math.floor(Math.random()*musicSource.length);
document.write('<embed src="'+musicSource[rand]+'" autoplay="true" hidden="true" loop="true" />');

// -->
</script>

</body>
</html>