Log In · Register

 
Help with JukeBox Script
voltigeur
post Mar 21 2007, 09:34 PM
Post #1


Newbie
*

Group: Member
Posts: 6
Joined: Feb 2006
Member No: 380,851



Hey guys, I was wondering if someone could help me figure out the problem with my (i ripped part of it from createblog.com.. so it isn't quite mine) script. ermm.gif

You see, the main issue I'm facing right now is that the player simply wouldn't shuffle and play the next song on the list (as it should). It would just constantly repeat the same song that plays right at the start whenever the page loads up.

I would really appreciate it if someone could help me out with this!

edit: I removed the forms section cause I don't want a dropdown list to show up on my blog.

Here's the script:


===========================================================

CODE
<!-- begin code provided by createblog.com -->
<object id="darkplayer"

codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.c

ab#Version=5,1,52,701" type="application/x-oleobject" height="0"

standby="Loading Microsoft Windows Media Player components..." width="0"

classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">
<param NAME VALUE>
<param NAME="ShowControls" VALUE="0">
<param NAME="ShowStatusBar" VALUE="0">
<param NAME="ShowDisplay" VALUE="0">
<param NAME="DefaultFrame" VALUE="Slide">
<param NAME="Autostart" VALUE="1">
<param NAME="Loop" VALUE="True">
</object>

<script Language="JavaScript">
<!--
var playstate = 1;

var shuffle = true;  // false = shuffle off, true = shuffle on

var autoStart = true;   // false = autoStart off, true = autoStart on

songs=new Array();

// Add song URLs here
songs[0]="songurl1";
songs[1]="songurl2";
songs[2]="songurl3";

if (shuffle == 1) {
var randsg = Math.floor(Math.random()*songs.length);
document.darkplayer.FileName = songs[randsg];
document.darkplayer.src = songs[randsg];
}
function play(list) {
if (playstate == 2) {
document.darkplayer.Play();
} else {
var snum = list.options[list.selectedIndex].value
document.darkplayer.FileName = songs[snum];
document.darkplayer.src = songs[snum];
}
playstate = 1;
}
//-->
</script>
<!-- end code provided by createblog.com -->


This post has been edited by moorepocket*: Mar 21 2007, 10:59 PM
 
 
Start new topic
Replies
moorepocket
post Jun 5 2007, 10:45 PM
Post #2


Death is a promise given to us at birth
*******

Group: Official Designer
Posts: 4,757
Joined: Mar 2004
Member No: 7,459



i fibbed with your code a little.

CODE
<object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="0" height="0">
<param value="invisible" name="uiMode"/>
<param value="False" name="Autostart"/>
</object>

<form id="form">

<select id="playlist">

<!-- Add song info that appears in drop down list here -->
<option value="0"/>Dare You To Move
<option value="1"/>The Shadow Proves The Sunshine
<option value="2"/>Love Theme from St. Elmo's Fire

</select>

<br/>
<button id="BackButton" onclick="Back(forms['form'].playlist);"> << </button>
<button id="PlayPauseButton" onclick="PlayPause(forms['form'].playlist);"><strong> Play </strong></button>
<button id="NextButton" onclick="Next(forms['form'].playlist);"> >> </button>
<button id="StopButton" onclick="Stop();"><strong>Stop<strong></button>
<b><font color="white">Shuffle</font></b><input id="ShuffleSwitch" checked value="ON" onclick="ToggleShuffle(this);" type="checkbox"/>

</form>



<comment id="PlayHTML"><strong> Play <strong></comment>
<comment id="ShuffleOnHTML"><input id="ShuffleSwitch" checked onclick="ToggleShuffle(this);" type="checkbox"/></comment>
<comment id="ShuffleOffHTML"><input id="ShuffleSwitch" unchecked onclick="ToggleShuffle(this);" type="checkbox"/></comment>


<script id="Main" language="JavaScript">

var songs = new Array();

//*******************************//
//****** CHANGEABLE STUFF *******//
//*******************************//

var shuffle = true; // false = shuffle off, true = shuffle on

var autoStart = true; // false = autoStart off, true = autoStart on

var numberTracks = false; // true = place track number in front of list items, false = no track numbers

// Add song URLs here (make sure it matches up with the order you have for song info, and urls need quotes):
songs[0]="http://www.fileden.com/files/2007/1/1/579683/Switchfoot%20-%20Dare%20You%20to%20Move.mp3";
songs[1]="http://www.fileden.com/files/2007/1/1/579683/Switchfoot%20-%20The%20Shadow%20Proves%20The%20Sunshine.mp3";
songs[2]="http://www.fileden.com/files/2007/1/1/579683/David%20Foster%20-%20Love%20Theme%20from%20%27%27St.%20Elmo%27s%20Fire%27%27.mp3";


//*******************************//
//*******************************//

// Initializations //
with (document){
var length = forms['form'].playlist.length;

if(numberTracks){
for (var i = 0; i < length; i++){
forms['form'].playlist.options[i].innerHTML = (i+1) + " - " + forms['form'].playlist.options[i].innerHTML;
}
}

if (shuffle) {
var randsg = Math.floor(Math.random()*songs.length);
Player.url = songs[randsg];
forms['form'].playlist.options[randsg].selected = true;
forms['form'].ShuffleSwitch.outerHTML = ShuffleOnHTML.innerHTML;
}

else {
forms['form'].ShuffleSwitch.outerHTML = ShuffleOffHTML.innerHTML;
Player.url = songs[0];
}

if(autoStart){
var snum = forms['form'].playlist.selectedIndex;
if(Player.url != songs[snum]){
Player.url = songs[snum];
}
Player.controls.Play();
}
}

// Functions //
// Description: "PlayPause" will toggle playing and pausing if the same song is still selected,
// otherwise it will load the newly selected song
function PlayPause(list) {
var snum = list.selectedIndex;

if((Player.url == songs[snum] && Player.url != "") && Player.playState != 1){
if(Player.playState == 3){
Player.controls.Pause();
}

else {
Player.controls.Play();
}
}

else {
Player.url = songs[snum];
Player.controls.Play();
}
}

// Description: "Next" will move to the next music file if shuffle is off
// otherwise it will load a random song. Calls PlayPause to start music.
function Next(list) {
var snum = list.selectedIndex;
if (!shuffle) {
if (snum == list.length-1) {
snum = -1;
}
snum++;
}

else {
var temp;
do{
temp = Math.floor(Math.random()*songs.length);
} while(temp == snum);
snum = temp;
}

list.options[snum].selected = true;
PlayPause(list);
}

// Description: "Back" does the same thing as "Next" but moves backwads
// through the list. If shuffle is on then picks a random song.
function Back(list) {
var snum = list.selectedIndex;
if (!shuffle) {
if (snum == 0){
snum = list.length;
}
snum--;
}

else {
var temp;
do{
temp = Math.floor(Math.random()*songs.length);
} while(temp == snum);
snum = temp;
}

list.options[snum].selected = true;
PlayPause(list);
}

// Description: Self explanitory.
function Stop(){
Player.controls.Stop();
}

// Description: Makes the shuffle flag the same as the status of the CheckBox
// The status of the checkbox (true/false) indicates if the box is checked
function ToggleShuffle(CheckBox) {
shuffle = CheckBox.status;
}

</script>

<script id="StateChangeHandler" for="Player" language="JavaScript" event="playStateChange(NewState)">

// Description: This is an interupt handler used to handle instances when the
// state of the player changes to play or stop for example.

//STATE.innerText = NewState;

switch(NewState){
case 8: // Handles player after it just finishes playing through a song
var num = document.forms['form'].playlist.selectedIndex;

if (!shuffle){
if(num == document.forms['form'].playlist.length-1){
num = -1;
}

num++;
}
else {
var temp;
do{
temp = Math.floor(Math.random()*songs.length);
} while(temp == num);
num = temp;
}

document.forms['form'].playlist.options[num].selected = true;

PreviousState = NewState;
break;

case 1: // Handles player after it stops
if(PreviousState == 8){
var num = document.forms['form'].playlist.selectedIndex;
Player.settings.autoStart = true;
Player.url = songs[num];
PreviousState = NewState;
}

else if (PreviousState != 3 && PreviousState != 2){
Player.controls.Play();
Player.settings.autoStart = false;
}

else{
forms['form'].PlayPauseButton.innerHTML = PlayHTML.innerHTML;
}
break;

case 3: // Handles player after it starts to play
PreviousState = NewState;
forms['form'].PlayPauseButton.innerHTML = "Pause";
shuffle = document.forms['form'].ShuffleSwitch.status;
break;

case 2: // Handles player after being paused
PreviousState = NewState;
forms['form'].PlayPauseButton.innerHTML = PlayHTML.innerHTML;
break;

default:
}

</script>
 

Posts in this topic


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: