Solved

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

Posted on 2004-10-03
16
156 Views
Last Modified: 2010-04-03
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.!
0
Comment
Question by:virtex
  • 9
  • 4
  • 3
16 Comments
 
LVL 10

Expert Comment

by:muso120999
ID: 12212767
Can you add an extract of playlist.xml that we can look at too?
0
 
LVL 1

Author Comment

by:virtex
ID: 12213393
<playlist>
 <mp3file track="song1.mp3"/>
 <mp3file track="song2.mp3"/>
 <mp3file track="song3.mp3"/>
 <mp3file track="song4.mp3"/>
 <mp3file track="song5.mp3"/>
</playlist>

0
 
LVL 7

Assisted Solution

by:ssdesign
ssdesign earned 500 total points
ID: 12216565
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:virtex
ID: 12218432
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
 
LVL 1

Author Comment

by:virtex
ID: 12218448
and play song which is the randomplayer mc
0
 
LVL 7

Expert Comment

by:ssdesign
ID: 12235767
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
 
LVL 1

Author Comment

by:virtex
ID: 12236385
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
 
LVL 7

Expert Comment

by:ssdesign
ID: 12248375
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
 
LVL 7

Expert Comment

by:ssdesign
ID: 12257369
Hi, Any success? Let me know where you are stuck and we can resolve it.
0
 
LVL 1

Author Comment

by:virtex
ID: 12262917
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
 
LVL 1

Author Comment

by:virtex
ID: 12267308
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
 
LVL 10

Accepted Solution

by:
muso120999 earned 0 total points
ID: 12267328
> 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
 
LVL 1

Author Comment

by:virtex
ID: 12268166
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
 
LVL 1

Author Comment

by:virtex
ID: 12268174
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
 
LVL 10

Expert Comment

by:muso120999
ID: 12268195
>  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
 
LVL 1

Author Comment

by:virtex
ID: 12272755
btw, seems there is another error in here. it wont play intil you press the play button twice. any help?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question