[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-10-03
16
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

650 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