Wednesday, September 18, 2024

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:

//create an onEnterFrame event with
//listener capabilities
ASBroadcaster.initialize(Movieclip);
_root.createEmptyMovieClip("__enterFrame",-9799);
__enterFrame.onEnterFrame=function(){
Movieclip.broadcastMessage("onEnterFrame");
}
mysound=new Sound(this);
mysound.loadSound("an_mp3.mp3");
mysound.onLoad=function(){
&nbsp&nbsp Movieclip.addListener(this);
&nbsp&nbsp //redefine the onLoad event handler
&nbsp&nbsp this.onLoad=function(){
&nbsp&nbsp&nbsp //iterate over all the id3 tags
&nbsp&nbsp&nbsp //and trace their names and values
&nbsp&nbsp&nbsp for(var i in this.id3){
&nbsp&nbsp&nbsp&nbsp trace(i+":"+this.id3[i]);
&nbsp&nbsp&nbsp }
&nbsp }
&nbsp&nbsp //when the onEnterFrame broadcast
&nbsp&nbsp //is recieved, call the newly defined
&nbsp&nbsp //onLoad evet handler and then
&nbsp&nbsp //stop listening to the broadcast
&nbsp&nbsp this.onEnterFrame=function(){
&nbsp&nbsp&nbsp this.onLoad();
&nbsp&nbsp&nbsp Movieclip.removeListener(this);
&nbsp&nbsp delete this.onEnterFrame;
&nbsp&nbsp }
}

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.

Guy Watson (or FlashGuru as he is also known) has been an active, well
recognized figure in the Flash community for over four years,
supporting the community with tutorials, source files, moderating the
Flashkit forums, and running his own Flash resource Web site,
FlashGuru’s MX 101. Guy was one of two developers who created the ever
popular, award winning zoom interface for Relevare and now runs his
own company, FlashGuru LTD, which builds Flash Games & Applications
for clients such as Comic Relief, Egg and Channel 4.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

← back to caymas new homes in naples fl. Social media marketing.