I am trying to have a streamed mp3 loaded from xml, randomly play a new song on complete. I already have it play randomly onload. Here is what I have, and it doesnt work :\
tickerLength = 52;
for (i=0; i<tickerLength; i++) {
leading += " ";
}
display.content = leading+"music...";
display.contentPos = 0;
display.delay = 5;
display.counter = 0;
one.enabled = false;
two.enabled = false;
three.enabled = false;
four.enabled = false;
five.enabled = false;
InitiateSong = function () {
var my = playlist.songs[playlist.currSong];
display.contentPos = 0;
playlist.soundObj.stop();
playlist.soundObj = new Sound();
playlist.soundObj.loadSound(my.url, true);
myMusicVolume = 100;
playlist.soundObj.setVolume(MyMusicVolume);
};
playlist = new XML();
playlist.ignoreWhite = true;
playlist.load("http://www.enervated.com/scribbles/audio/playlist.xml");
playlist.onLoad = function() {
this.soundObj = new Sound();
this.songs = new Array(this.childNodes.length);
for (i=0; i<this.songs.length; i++) {
var my = this.childNodes*;
this.songs* = {};
this.songs*.name = my.nodeName;
for (props in my.attributes) {
this.songs*[props] = my.attributes[props];
}
}
playlist.onSoundComplete = function() {
choice = Math.round(Math.random()*4);
if (choice == 0) {
this.currSong = 0;
break;
} else if (choice == 1) {
this.currSong = 1;
break;
} else if (choice == 2) {
this.currSong = 2;
break;
} else if (choice == 3) {
this.currSong = 3;
break;
} else if (choice == 4) {
this.currSong = 4;
break;
}
InitiateSong();
}
choice = Math.round(Math.random()*4);
if (choice == 0) {
this.currSong = 0;
break;
} else if (choice == 1) {
this.currSong = 1;
break;
} else if (choice == 2) {
this.currSong = 2;
break;
} else if (choice == 3) {
this.currSong = 3;
break;
} else if (choice == 4) {
this.currSong = 4;
break;
}
InitiateSong();
one.enabled = true;
two.enabled = true;
three.enabled = true;
four.enabled = true;
five.enabled = true;
};
this.onEnterFrame = function() {
with (display) {
if (!(counter++%delay)) {
if (playlist.soundObj.position) {
var secs = Math.floor(playlist.soundObj.position/1000);
var mins = Math.floor(secs/60);
secs %= 60;
if (secs<10) {
secs = "0"+secs;
}
if (mins<10) {
mins = "0"+mins;
}
var my = playlist.songs[playlist.currSong];
content = leading+"playing "+my.title+" by "+my.artist+" from the album "+my.album+" - ["+mins+":"+secs+"]";
}
text = content.substr(contentPos, tickerLength);
if (++contentPos == content.length) {
contentPos = 0;
}
}
}
};
one.onRelease = function() {
playlist.currSong = 0;
InitiateSong();
};
two.onRelease = function() {
playlist.currSong = 1;
InitiateSong();
};
three.onRelease = function() {
playlist.currSong = 2;
InitiateSong();
};
four.onRelease = function() {
playlist.currSong = 3;
InitiateSong();
};
five.onRelease = function() {
playlist.currSong = 4;
InitiateSong();
};
off.onPress = function() {
playlist.soundObj.stop();
playlist.soundObj = new Sound();
display.content = "";
};
here is the final result: www.enervated.com
thanks in advance.