xml playlist id3 for flash and how to make one and play info.

I am currently messing around with a lil bit of code. never used xml b4. here it is

var tracklist = new Array ();
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
 if (!success)
 {
   return;
 }
 var topLevel = null;
 for (i = 0; i <= this.childNodes.length; i++)
 {
   if (this.childNodes[i].nodeValue == null &&
       this.childNodes[i].nodeName == "playlist")
   {
     topLevel = this.childNodes[i];
     break;
   }
 }
 if (topLevel != null)
 {
   for (i = 0; i <= topLevel.childNodes.length; i++)
   {
     if (topLevel.childNodes[i].nodeName == "mp3file")
     {
       var track =
           topLevel.childNodes[i].attributes["track"];
       _root.tracklist.push (track);
     }
   }
 }
}
function randomBetween (a, b)
{
 return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
 var track = _root.track;
 if (track.getBytesLoaded () == track.getBytesTotal () &&
     track.duration > 0)
 {
   clearInterval (_root.checkLoaded);
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.songname +
       newline;
   trackID3Info.text += "Artist: " + track.id3.artist +
       newline;
   trackID3Info.text += "Album: " + track.id3.album +
       newline;
   trackID3Info.text += "Year: " + track.id3.year + newline;
   trackID3Info.text += "Comments: " + track.id3.comment +
       newline;
 }
}
randomPlayer.onPress = function ()
{
 stopAllSounds ();
 var trackNo = randomBetween (0, trackInfo.length - 1);
 var track = new Sound ();
 track.onID3 = function ()
 {
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
   trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
   trackID3Info.text += "Album: " + track.id3.TALB + newline;
   trackID3Info.text += "Year: " + track.id3.TYER + newline;
   trackID3Info.text += "Comments: " + track.id3.COMM +
       newline;
 };
 track.loadSound (tracklist[trackNo], true);
};

It loads up a mp3 from xml then gets id3.

I would like to know what I should be doing from here to get it to play. the mc has 3 buttons, a dynamic text box and a background. buttons are forwards backwards and play. if you can complete this please let me know. graphics can be generic. Thanks alot.

500 points goes out to the person who gives me back a working result using the above information.!
LVL 1
virtexAsked:
Who is Participating?
 
muso120999Connect With a Mentor Commented:
> but it still plays. Any ideas?

Don't accept this as an answer - I'm just making a comment...

Can't you just stop the sound with stopAllSounds();?
0
 
muso120999Commented:
Can you add an extract of playlist.xml that we can look at too?
0
 
virtexAuthor Commented:
<playlist>
 <mp3file track="song1.mp3"/>
 <mp3file track="song2.mp3"/>
 <mp3file track="song3.mp3"/>
 <mp3file track="song4.mp3"/>
 <mp3file track="song5.mp3"/>
</playlist>

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
ssdesignConnect With a Mentor Commented:
Hi,
Here is your solution.

This works perfectly, I tested it out as well.

//-----------------------------------------------------
//-----------------------------------------------------

var tracklist = new Array ();
var track ="";
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
 if (!success)
 {
   return;
 }
 var topLevel = null;
 trace("CHILD: "+this.childNodes.length);
 for (i = 0; i <= this.childNodes.length; i++)
 {
   if (this.childNodes[i].nodeValue == null &&
       this.childNodes[i].nodeName == "playlist")
   {
     topLevel = this.childNodes[i];
       trace("testing"+topLevel);
      
     break;
   }
 }
 if (topLevel != null)
 {
       trace("TOPLEVEL: "+topLevel.childNodes.length);
      
   for (i = 0; i <= topLevel.childNodes.length; i++)
   {
     if (topLevel.childNodes[i].nodeName == "mp3file")
     {
       
           var track = topLevel.childNodes[i].attributes["track"];
               trace("THIS IS PROBLEM: "+topLevel.childNodes[i].attributes["track"]);
                   _root.tracklist.push (track);
     }
      
      // trace("sajid:"+_root.tracklist);
   }
 }
 trace(tracklist);
}
function randomBetween (a, b)
{
 return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
 var track = _root.track;
 trace("THIS IS TRACK: "+track);
 if (track.getBytesLoaded () == track.getBytesTotal () &&
     track.duration > 0)
 {
   clearInterval (_root.checkLoaded);
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.songname +
       newline;
   trackID3Info.text += "Artist: " + track.id3.artist +
       newline;
   trackID3Info.text += "Album: " + track.id3.album +
       newline;
   trackID3Info.text += "Year: " + track.id3.year + newline;
   trackID3Info.text += "Comments: " + track.id3.comment +
       newline;
 }
}
randomPlayer.onPress = function ()
{
 stopAllSounds ();
 var trackNo = randomBetween (0, tracklist.length - 1);
 trace("rand Tracn No: "+trackNo);
 var track = new Sound ();
 track.onID3 = function ()
 {
       trace("ON ID# CALLED");
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
   trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
   trackID3Info.text += "Album: " + track.id3.TALB + newline;
   trackID3Info.text += "Year: " + track.id3.TYER + newline;
   trackID3Info.text += "Comments: " + track.id3.COMM +
       newline;
      trace("Album: " + track.id3.TALB + newline);
 };
 track.loadSound (tracklist[trackNo], true);
 
};

//-----------------------------------------------------
//-----------------------------------------------------

There was a problem with "trackInfo.length"

trackInfo is not getting defined anywhere, actually it should have been, "tracklist.length"

Copy my code into your timeline and then place a movieclip on stage called "randomPlayer" and bingo :)
0
 
virtexAuthor Commented:
great that part works. how do you get it to go back a song or forward a song though using that method? if you can do that for me it would be very appreciated. basically like I originally said I have a back a song button and a forward a song button.
0
 
virtexAuthor Commented:
and play song which is the randomplayer mc
0
 
ssdesignCommented:
Ok replace the code i gave earlier with this:

//------------------------------------------------
//------------------------------------------------

var tracklist = new Array ();
var track ="";
currentSong = "";
var mp3List = new XML ();
mp3List.ignoreWhite = true;
mp3List.onLoad = createPlayList;
mp3List.load ("playlist.xml");
function createPlayList (success)
{
 if (!success)
 {
   return;
 }
 var topLevel = null;
 trace("CHILD: "+this.childNodes.length);
 for (i = 0; i <= this.childNodes.length; i++)
 {
   if (this.childNodes[i].nodeValue == null &&
       this.childNodes[i].nodeName == "playlist")
   {
     topLevel = this.childNodes[i];
       trace("testing"+topLevel);
      
     break;
   }
 }
 if (topLevel != null)
 {
       trace("TOPLEVEL: "+topLevel.childNodes.length);
      
   for (i = 0; i <= topLevel.childNodes.length; i++)
   {
     if (topLevel.childNodes[i].nodeName == "mp3file")
     {
       
           var track = topLevel.childNodes[i].attributes["track"];
               trace("THIS IS PROBLEM: "+topLevel.childNodes[i].attributes["track"]);
                   _root.tracklist.push (track);
     }
      
      // trace("sajid:"+_root.tracklist);
   }
 }
 trace(tracklist);
}
function randomBetween (a, b)
{
 return Math.min (a, b) + random (Math.abs (a - b) + 1);
}
function playTrack ()
{
 var track = _root.track;
 trace("THIS IS TRACK: "+track);
 if (track.getBytesLoaded () == track.getBytesTotal () &&
     track.duration > 0)
 {
   clearInterval (_root.checkLoaded);
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.songname +
       newline;
   trackID3Info.text += "Artist: " + track.id3.artist +
       newline;
   trackID3Info.text += "Album: " + track.id3.album +
       newline;
   trackID3Info.text += "Year: " + track.id3.year + newline;
   trackID3Info.text += "Comments: " + track.id3.comment +
       newline;
 }
}
randomPlayer.onPress = function ()
{
 stopAllSounds ();
 var trackNo = randomBetween (0, tracklist.length - 1);
 currentSong = trackNo;
 trace("rand Tracn No: "+trackNo);
 loadSong(currentSong);
}

function loadSong(tNo){
      var track = new Sound ();
 track.onID3 = function ()
 {
       trace("ON ID# CALLED");
   trackID3Info.text = "";
   trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
   trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
   trackID3Info.text += "Album: " + track.id3.TALB + newline;
   trackID3Info.text += "Year: " + track.id3.TYER + newline;
   trackID3Info.text += "Comments: " + track.id3.COMM +
       newline;
      trace("Album: " + track.id3.TALB + newline);
 };
 track.loadSound (tracklist[tNo], true);
}

function playNext(){
                ++currentSong;
      trace("THIS IS CURRENT: "+currentSong);
      if(_root.currentSong <=(_root.tracklist.length-1)){
            //trace(_root.currentSong +": AND :"+(_root.tracklist.length - 1));
            _root.loadSong(_root.currentSong);
      } else {
            _root.nextPlayer.enabled=false;
      }
}

function playPrev(){
                --currentSong;
      trace("THIS IS CURRENT: "+currentSong);
      if(_root.currentSong >= 0){
            //trace(_root.currentSong +": AND :"+(_root.tracklist.length - 1));
            _root.loadSong(_root.currentSong);
      } else {
            _root.nextPlayer.enabled=false;
      }
}

//------------------------------------------------
//------------------------------------------------


I added two more functions called:

playNext()
and
playPrev()

Call these functions to move to next or previous songs.

You can call then on button actions like this:

on(release){
         _root.playNext();
}

or

on(release){
         _root.playPrev();
}
0
 
virtexAuthor Commented:
now there is only one problem with this. if I start it up it will continue to play the mp3 that was playing b4 and play the next one at the same time. I tried doing a track.sound.stop();

but it still plays. Any ideas?
0
 
ssdesignCommented:
On my cmoputer it does not play the previous song. Because when you loadSound, it should automatically unload the first one.

I will see what i can figure out more here.
0
 
ssdesignCommented:
Hi, Any success? Let me know where you are stuck and we can resolve it.
0
 
virtexAuthor Commented:
none, it still plays the second one over the first one. If it is possible could you replace the random with just a straight play and on hit again stop then use the 2 other buttons to play one forward or one backward?

Please let me know. seems it isnt unloading it still.
0
 
virtexAuthor Commented:
could you post the .fla so I can see what I am doing wrong compared to what you are doing? Please let me know. thanks!
0
 
virtexAuthor Commented:
yay!, that actually worked,
on(release){
       stopAllSounds();
       _root.playPrev();
}

I will give you some points for that still lol
I forgot all about that.
0
 
virtexAuthor Commented:
Will figure out a way of getting you some points. maybe another way to do it. thnx still. was just weird and I forgot about that command :/
0
 
muso120999Commented:
>  Will figure out a way of getting you some points

Really, don't worry about it ;-)

I just wanted to help, ssdesign did all of the hard work!
0
 
virtexAuthor Commented:
btw, seems there is another error in here. it wont play intil you press the play button twice. any help?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.