Link to home
Start Free TrialLog in
Avatar of virtex
virtex

asked on

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.!
Avatar of muso120999
muso120999

Can you add an extract of playlist.xml that we can look at too?
Avatar of virtex

ASKER

<playlist>
 <mp3file track="song1.mp3"/>
 <mp3file track="song2.mp3"/>
 <mp3file track="song3.mp3"/>
 <mp3file track="song4.mp3"/>
 <mp3file track="song5.mp3"/>
</playlist>

SOLUTION
Avatar of ssdesign
ssdesign

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of virtex

ASKER

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.
Avatar of virtex

ASKER

and play song which is the randomplayer mc
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();
}
Avatar of virtex

ASKER

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?
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.
Hi, Any success? Let me know where you are stuck and we can resolve it.
Avatar of virtex

ASKER

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.
Avatar of virtex

ASKER

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!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of virtex

ASKER

yay!, that actually worked,
on(release){
       stopAllSounds();
       _root.playPrev();
}

I will give you some points for that still lol
I forgot all about that.
Avatar of virtex

ASKER

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 :/
>  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!
Avatar of virtex

ASKER

btw, seems there is another error in here. it wont play intil you press the play button twice. any help?