# Help with XML driven MP3 Player

**URL:** <https://forum.kirupa.com/t/help-with-xml-driven-mp3-player/219187>\
**Category:** flash\
**Created:** [March 14, 2007, 3:52pm UTC](https://forum.kirupa.com/t/help-with-xml-driven-mp3-player/219187 "2007-03-14T15:52:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![odine](https://avatars.discourse-cdn.com/v4/letter/o/a5b964/32.png) [@odine](https://forum.kirupa.com/u/odine)\
**Post date:** [March 14, 2007, 3:52pm UTC](https://forum.kirupa.com/t/help-with-xml-driven-mp3-player/219187/1 "2007-03-14T15:52:23Z")

</div>

Hey Guys,

I have a very frustrating issue!

I am trying to integrate an MP3 player into a flash site im building. I have made it as far as to integrate a player i grabbed off the web, with some modifications. It is an MP3 Player with an XML playlist, which is exactly what i want. The only this this player does not have which I NEED! i cannot stress enough, --NEED-- is for the music to play streaming, with the current scripting it requires 100% preload of the mp3 before the play function is called through (ie. bytesloaded == bytestotal)

I though it would be as simple as saying something along the lines of if loaded = 5% of total, play. but no matter what i did to try to make this work it produced no results whatsoever.

What i need is to have a player with the key elements: play, pause, next, artist and track info and progress bar (seekable) with a button to expand and hide the playlist. I cannot believe to my utter disbelief that there is no single flash mp3 player that i have found (in 4 hours of searching) that has these simple requirements (streaming and collapsable XML driven playlist)

Here is the code for the current player im modding, but any other suggestiongs for decent players (fully customizable skin is required) i would certainly be open to them.

[AS]//defines a new sound object  
music = new Sound(this);  
trkInfo = new Date();

//comment these three lines if you don’t want it to play on startup  
playing = false;  
paused = false;  
loading = true;  
///////////////////////////////////////////////////////////////////  
//sets the beginning slider attributes  
vol\_mc.slider\_mc.\_x = 70;  
bal\_mc.slider\_mc.\_x = 50;  
pos\_mc.slider\_mc.\_x = 0;  
pos\_mc.slider\_mc.\_visible = false;  
vol\_mc.slider\_mc.slider.useHandCursor = false;  
bal\_mc.slider\_mc.slider.useHandCursor = false;  
pos\_mc.slider\_mc.slider.useHandCursor = false;  
scroller\_mc.slider\_mc.slider.useHandCursor = false;  
loop\_mc.radio\_mc.useHandCursor = false;  
shuffle\_mc.radio\_mc.useHandCursor = false;  
//controls which song is highlighted in the playlist, see attacher  
function select(){  
for(i in playlist\_mc.target\_mc){  
if(playlist\_mc.target\_mc\*.songNum != songNum){  
playlist\_mc.target\_mc\*.gotoAndStop(1);  
}  
else{  
playlist\_mc.target\_mc\*.gotoAndStop(2);  
}

}

}  
songNum = 0;  
numTracks = songInfo.content.length;  
//attacher: attaches the playlist movies, select() is called here  
for(i = 0; i \< numTracks; i++){  
songInfo.content\*.songNum = i;  
playlist\_mc.target\_mc.attachMovie(“playlistItem”, “item” + i, (i+1), songInfo.content\*);  
playlist\_mc.target\_mc[“item” + i].\_y = i \* 18;  
if(playlist\_mc.target\_mc[“item” + i].title == songInfo.content[songNum].title){  
playlist\_mc.target\_mc[“item” + i].gotoAndStop(2);  
}  
else{  
playlist\_mc.target\_mc[“item” + i].gotoAndStop(1);  
}  
}  
scrollWindowHeight = 72;  
scrollMax = (playlist\_mc.target\_mc.\_y + playlist\_mc.target\_mc.\_height) - scrollWindowHeight;  
//if there’s not enough to scroll, there will be no handle  
if(playlist\_mc.\_height \<= scrollWindowHeight){  
scroller\_mc.slider\_mc.\_visible = false;  
}  
else{  
scroller\_mc.visible = true;  
}  
//loads the song  
music.loadSound(songInfo.content[songNum].path, false);  
//this is what makes the music fade when you hit the stop button  
function fadeOut() {  
if (music.getVolume()\>0) {  
music.setVolume(music.getVolume()-5);  
} else {  
music.stop();  
pos\_mc.slider\_mc.\_visible = false;  
pos\_mc.slider\_mc.\_x = 0;  
}  
}  
//this function is called when the first song ends, or the next button is press. It moves to the next song  
function nextSong(){  
if(loop == true and skipLoop != true){  
music.stop();  
music.start(0, 0);  
}  
else{  
if(shuffle == true){  
songNum = Math.floor(Math.random()\*(numTracks-1));  
}  
else{  
songNum++;  
if(songNum == songInfo.content.length){  
songNum = 0;  
}  
}  
loading = true;  
playing = false;  
paused = false;  
select();  
if(skipLoop == true){  
skipLoop = false;  
}  
music.loadSound(songInfo.content[songNum].path, false);  
}

}  
//self explantory =)  
function prevSong(){  
songNum–;  
if(songNum \< 0){  
songNum = songInfo.content.length - 1;  
}

loading = true;  
playing = false;  
paused = false;

select();  
music.loadSound(songInfo.content[songNum].path, false);

}  
//this function controls the text in the info window and what actions the player will take next based on what button is pressed  
this.onEnterFrame = function() {  
dur = music.duration;  
pos = music.position;  
total = music.getBytesTotal();  
loaded = music.getBytesLoaded();

//preloader  
if (loading == true) {  
if (music.getBytesLoaded() == music.getBytesTotal() and dur \> 0){  
loading = false;  
playing = true;  
music.start(0,0);  
music.setVolume(vol\_mc.slider\_mc.\_x);  
music.setPan((bal\_mc.slider\_mc.\_x-50)\*2);  
status = “playing”;  
pos\_mc.slider\_mc.\_visible = true;  
}  
else{  
pos\_mc.slider\_mc.\_visible = false;

if(music.getBytesTotal() != undefined){  
artist = Math.round(music.getBytesLoaded()/music.getBytesTotal()\*100)+"% loaded";  
}  
else{  
artist = undefined;  
}

title = undefined;  
status = “loading”;  
}  
}

//updates the sound attributes (vol, bal, etc…) and displays their info in the text fields  
else if (playing == true) {  
vol = music.getVolume() + “%”;  
bal = music.getPan();  
if(whichDrag != “pos\_mc”){  
pos\_mc.slider\_mc.\_x = (music.position/music.duration)\*100;  
}

music.setVolume(vol\_mc.slider\_mc.\_x);  
music.setPan((bal\_mc.slider\_mc.\_x-50)\*2);  
titleArtist = songInfo.content[songNum].path;  
title = songInfo.content[songNum].title;  
artist = songInfo.content[songNum].artist;  
music.onSoundComplete = nextSong;

} else{  
titleArtist = undefined;  
fadeOut();  
status = “stopped”;  
}

//controls the scrolling of the playlist  
if(scrolling == true){  
if(playlist\_mc.\_height \> scrollWindowHeight){  
percentScroll = (scroller\_mc.slider\_mc.\_y/(scroller\_mc.scrollBg\_mc.\_y + scroller\_mc.scrollBg\_mc.\_height));  
scrollValue = scrollMax\*percentScroll;  
playlist\_mc.target\_mc.\_y = -(scrollValue);  
}  
}

//displays the time  
if(timeWay == “forward” or timeWay == undefined){  
trkInfo.setSeconds(music.position/1000);  
trkInfo.setMinutes((music.position/1000)/60);  
trkInfo.setHours((music.position/1000)/3600);  
}  
else{  
trkInfo.setSeconds((music.duration -music.position)/1000);  
trkInfo.setMinutes(((music.duration -music.position)/1000)/60);  
trkInfo.setHours(((music.duration -music.position)/1000)/3600);  
}  
seconds = trkInfo.getSeconds();  
minutes = trkInfo.getMinutes();  
hours = trkInfo.getHours();

if(seconds \< 10){  
seconds = 0 + seconds.toString();  
}  
if(minutes \< 10){  
minutes = 0 + minutes.toString();  
}  
if(hours \< 10){  
hours = 0 + hours.toString();  
}

trkHrs = Math.floor((music.duration/1000)/3600);  
trkMin = Math.floor((music.duration/1000)/60);  
trkSec = Math.floor((music.duration/1000) - (60\*trkMin));  
if(trkSec \< 10){  
trkSec = 0 + trkSec.toString();  
}  
if(trkMin \< 10){  
trkMin = 0 + trkMin.toString();  
}  
if(trkHrs \< 10){  
trkHrs = 0 + trkHrs.toString();  
}  
if(loading != true){  
time = hours + “:” + minutes + “:” + seconds;  
totalTrkTime = trkHrs + “:” + trkMin + “:” + trkSec;  
}  
else{  
time = undefined;  
totalTrkTime = undefined;  
}  
};  
///////////////////////////////end onEnterFrame///////////////////////////////

//controls the play button  
play\_mc.onRelease = play\_mc.onReleaseOutside = function() {  
if(playing != true or paused == true){  
if(loading != true){  
if(paused == true){  
seconds = pos/1000;  
music.start(seconds, 0);  
paused = false;  
}  
else if (loading != true) {  
loading = true;  
music.loadSound(songInfo.content[songNum].path, false);  
[//music.start](https://music.start)(0,0);  
}  
}  
}  
};  
//controls the stop button  
stop\_mc.onRelease = stop\_mc.onReleaseOutside = function () {  
//if(loading != true){  
loading =false;  
playing = false;  
paused = false;  
artist = undefined;  
title = undefined;  
//}  
};  
//controls the pause button  
pause\_mc.onRelease = pause\_mc.onReleaseOutside = function(){  
if(playing == true){  
if(paused == false){  
pos = music.position;  
music.stop();  
//playing = false;  
paused = true;  
}  
else{  
seconds = pos/1000;  
music.start(seconds, 0);  
paused = false;  
}  
}  
}  
//controls the next button  
next\_mc.onRelease = next\_mc.onReleaseOutside = function(){  
if(loading != true){  
skipLoop = true;  
nextSong();  
}  
}  
//controls the previous button  
back\_mc.onRelease = back\_mc.onReleaseOutside = function(){  
if(loading != true){  
prevSong();  
}  
}  
loop\_mc.radio\_mc.onRelease = shuffle\_mc.radio\_mc.onRelease = function(){  
if(this.\_parent.\_currentframe == 1){  
this.\_parent.gotoAndStop(2);  
}  
else{  
this.\_parent.gotoAndStop(1);  
}  
if(this.\_parent.\_name == “loop\_mc”){  
if(loop == true){  
loop = false;  
}  
else{  
loop = true;  
}  
}  
if(this.\_parent.\_name == “shuffle\_mc”){  
if(shuffle == true){  
shuffle = false;  
}  
else{  
shuffle = true;  
}  
}

}  
//controls the sliders  
vol\_mc.slider\_mc.slider.onPress = bal\_mc.slider\_mc.slider.onPress=pos\_mc.slider\_mc.slider.onPress=function () {  
whichDrag = this.\_parent.\_parent.\_name;  
this.\_parent.onMouseMove = function() {  
updateAfterEvent();  
};  
this.\_parent.startDrag(false, 0, this.\_y, 100, this.\_y);  
};  
vol\_mc.slider\_mc.slider.onRelease = vol\_mc.slider\_mc.slider.onReleaseOutside=  
bal\_mc.slider\_mc.slider.onRelease = bal\_mc.slider\_mc.slider.onReleaseOutside=  
pos\_mc.slider\_mc.slider.onRelease = pos\_mc.slider\_mc.slider.onReleaseOutside=  
function () {  
if(whichDrag == “pos\_mc”){  
if(pos\_mc.slider\_mc.\_x == 100){  
pos\_mc.slider\_mc.\_x = 99.5;  
}  
newPos = (pos\_mc.slider\_mc.\_x\*(music.duration/1000))/100;  
music.stop();  
music.start(newPos, 0);  
}  
whichDrag = undefined;  
beenDragged = “pos\_mc”;  
this.\_parent.onMouseMove = undefined;  
this.\_parent.stopDrag();  
if(bal\_mc.slider\_mc.\_x \> 47 and bal\_mc.slider\_mc.\_x \< 53){  
bal\_mc.slider\_mc.\_x=50;  
}  
};  
scroller\_mc.slider\_mc.slider.onPress = function(){  
scrolling = true;

this.\_parent.startDrag(0, this.\_parent.\_x, this.\_parent.\_parent.scrollBg\_mc.\_y,  
this.\_parent.\_x, this.\_parent.\_parent.scrollBg\_mc.\_y + this.\_parent.\_parent.scrollBg\_mc.\_height);  
}  
scroller\_mc.slider\_mc.slider.onRelease = function(){  
scrolling = false;  
this.\_parent.stopDrag();  
}  
//controls the button that changes the time display from time elapsed to time left, and vice versa  
timeButton\_mc.onRelease = function(){  
if(timeWay == undefined){  
timeWay = “back”;  
}  
else if(timeWay == “forward”){  
timeWay = “back”;  
}  
else if(timeWay == “back”){  
timeWay = “forward”;  
}  
}  
stop();[/AS]
