Friday, September 4, 2009

Pasre through the ID3 tags of an MP3 file with Actionscript 3

ID3 tags are the metadata attached to the mp3 files by the encoder. This contains information like the
#Song Name
#Artist
#Album
#Year
#Genre
#Comment
#Track Number.

This is how you access these data in flash:-
Hit Ctrl+j and bring up the Document Properties window and set both the width and height to 300 pixels. Select the first frame of the layer and hit F9 to bring up the Actions window. Copy and Paste the following code

/*Load the sound and play it though playing is not necessary for
viewing the ID3 tags*/

var mySound:Sound = new Sound(new URLRequest("myMusic.mp3"));
mySound.play();

/*Define a text field to view the tags*/
var id3Text:TextField = new TextField();
id3Text.x=50;
id3Text.y=50;
id3Text.autoSize = TextFieldAutoSize.LEFT;/*Resize keeping the upper left corner fixed*/
addChild(id3Text);

/*Display tags on completion of loading*/
mySound.addEventListener(Event.COMPLETE,onId3);

/*display the id3 tags*/
function onId3(e:Event) {
id3Text.appendText("Song : "+ mySound.id3.songName + "\n");
id3Text.appendText("Artist : "+ mySound.id3.artist + "\n");
id3Text.appendText("Album : "+ mySound.id3.album + "\n");
id3Text.appendText("Track No. : "+ mySound.id3.track + "\n");
id3Text.appendText("Year : "+ mySound.id3.year + "\n");
id3Text.appendText("Comment : "+ mySound.id3.comment + "\n");
}

Hit Ctrl+Enter to test your movie. Your tags should appear like this

1 comment:

  1. Perfect script! thank you :-)
    i'm trying to get id3 tags from my web radio
    but i can't :( can you help me please?
    My e-mail is: xrhstos33_@hotmail.com

    ReplyDelete