I had to make a couple of changes, but I got it working, thanks mate!!!
Had to add a _global.songurl = []; near the top, and add songurl[song_nr] to the next and prev buttons.
Also realised that having two "if" statements on the onEnterFrame function was doing weird things to the time display, but I've got that sorted now, as well as an "undefined" problem (didn't have all the childnodes listed in the onSoundComplete function).
Here's my fully working as for those who are interested:
stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
_global.songinfo = [];
_global.songurl = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
_global.songinfo[i] = playlist.firstChild.childNodes[i].attributes.info;
// add the following line
_global.songurl[i] = playlist.firstChild.childNodes[i].attributes.url;
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
// modify the following line
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
function timer(sound_obj) {
time = sound_obj.position/1000;
min = Math.floor(time/60);
min = (min<10) ? "0"+min : min;
sec = Math.floor(time%60);
sec = (sec<10) ? "0"+sec : sec;
timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
}
function duration (){
timed = _root.sound_mc.sound_obj.duration/1000;
mind = Math.floor(timed/60);
mind = (mind<10) ? "0"+mind : mind;
secd = Math.floor(timed%60);
secd = (secd<10) ? "0"+secd : secd;
totalDuration = mind+":"+secd;
}
// modify the following line
MovieClip.prototype.songStarter = function(file, name, band, info, url) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
display_txt.htmlText = name+" / "+band;
info_mc.info_text.html = true; // add this line
info_mc.info_text.htmlText = "<a href = \"" + url + "\">" + info + "<a/>"; // modify this line
timeInterval = setInterval(timer, 1000, this.sound_obj);
} else {
display_txt.text = "loading...";
info_mc.info_text.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
this.sound_obj.setVolume(50);
};
btn_play.onRelease = function() {
if (pause = true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
}
else {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.songStarter(songfile[song_nr]);
}
};
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true;//set the variable pause to true
}
btn_fw.onRelease = function() {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], songinfo[song_nr], songurl[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration,100);
You're a legend, Pax!!!
Maybe this should be added as an add-on to the mp3 player tutorial?