Old Articles - 6 years, 4 months ago - 0 Comments

Accessing ID3 Tags (external .mp3)

In Flash MX you have the capability to load an external mp3 sound file into a flash movie using the Sound.loadSound() method. In the latest release of the Flash 6 Player it is possible to access the ID3 tags embedded in an mp3 encoded file. Unfortuneatley you cannot access the ID3 tags in an mp3 file until it has *fully* loaded, this is fine when you are using the Sound.attachSound() method but it causes problems when you are loading an external sound into the player...

When an external sound has fully loaded into the player, you have to wait one frame before you can retrieve the values of the ID3 tags in the mp3. This means that you cannot access the ID3 tags inside of the Sound objects onLoad event handler. Here is some code that demonstrates how to access the ID3 tags from an external mp3 file loaded into the player using the Sound.loadSound() method:

Actionscript:
  1. //create an onEnterFrame event with
  2. //listener capabilities
  3. ASBroadcaster.initialize(Movieclip);
  4. _root.createEmptyMovieClip('__enterFrame',-9799);
  5. __enterFrame.onEnterFrame=function(){
  6.     Movieclip.broadcastMessage('onEnterFrame');
  7. }
  8. mysound=new Sound(this);
  9. mysound.loadSound('an_mp3.mp3');
  10. mysound.onLoad=function(){
  11.     Movieclip.addListener(this);
  12.     //redefine the onLoad event handler
  13.     this.onLoad=function(){
  14.         //iterate over all the id3 tags
  15.         //and trace their names and values
  16.         for(var i in this.id3){
  17.             trace(i+':'+this.id3[i]);
  18.         }
  19.     }
  20.     //when the onEnterFrame broadcast
  21.     //is recieved, call the newly defined
  22.     //onLoad evet handler and then
  23.     //stop listening to the broadcast
  24.     this.onEnterFrame=function(){
  25.         this.onLoad();
  26.         Movieclip.removeListener(this);
  27.         delete this.onEnterFrame;
  28.     }
  29. }

The same is true, for two other properties of the sound object, Sound.duration and Sound.position, you cannot access these properties until one frame after an external sound file has fully loaded, you can use the same process outlined above to retrieve the value of these two properties.



Note: This is an old article!

Please be aware that the content of this article may no longer be accurate and the links contained within could be broken.

Update Notifications

You can add our RSS feed to your favorite feed reader or recieve an email when a new article is posted by entering your email address below.

    Shu Player allows you to distribute your AIR Applications to users that dont have the AIR Runtime by converting them to standalone applications. Shu Player also adds more commands to do things like open external applications etc...


    If you hate the Adobe Updater like most of us, then just get rid of it.


    Want to quickly find out what version of the Flash Player a client has installed? Send them to www.playerversion.com


    Yet more pv3d goodness. Im loving this funky 3D Flash Lab, the work of Mathieu Badimon. [Update: Apparently this uses Five3D not PaperVision]


    There is an old interview with me on The FWA, its fairly long at 8 pages.


    If you do alot of travelling then it makes sense to get yourself a Priority Pass, which will get you access to over 500 airport lounges worldwide, regardless of whether your flying enconomy, business or first.


    Freelance Switch is a freelancer community with forums, jobs, daily tips and a complete 212 page e-book titled "How to be a rockstar freelancer" for sale.


    Lots of new media jobs at Creative Pool.


    BBC IPlayer is awesome, but its ashame that BBC News is still using Windows Media Player and Real video. Real player is officially badware.


More In Actionscript


More In Adobe Flash


More In Freelancing