Event.ID3

Listening for ID3 tags in ActionScript 3.0 is slightly different from ActionScript 2.0. In ActionScript 2.0, you used the onID3 event handler to detect when the ID3 information was detected, as seen in the following example:

var url:String = "http://www.helpexamples.com/flash/sound/song1.mp3";
var mp3:Sound = new Sound();
mp3.onID3 = function() {
var songInfo:Object = this.id3;
trace("ID3 loaded");
trace("\t artist: " + songInfo.artist);
trace("\t track: " + songInfo.track);
trace("\t comment: " + songInfo.comment);
trace("\t songName: " + songInfo.songName);
trace("\t album: " + songInfo.album);
trace("\t genre: " + songInfo.genre);
trace("\t year: " + songInfo.year);
}
mp3.loadSound(url, true);

In ActionScript 3.0, you instead use the addEventListener() method and a URLRequest object to load the sound, as seen in the following example:

var url:String = "http://www.helpexamples.com/flash/sound/song1.mp3";
var request:URLRequest = new URLRequest(url);
var mp3:Sound = new Sound(request);
mp3.addEventListener(Event.ID3, id3Handler)
mp3.play();

function id3Handler(event:Event):void {
var song:Sound = Sound(event.target);
var songInfo:ID3Info = ID3Info(song.id3);
trace("ID3 loaded");
trace("\t artist: " + songInfo.artist);
trace("\t track: " + songInfo.track);
trace("\t comment: " + songInfo.comment);
trace("\t songName: " + songInfo.songName);
trace("\t album: " + songInfo.album);
trace("\t genre: " + songInfo.genre);
trace("\t year: " + songInfo.year);
}

2 Responses to Event.ID3

  1. Steve says:

    Exactly what I was looking for!Noticed that MP3’s encoded with iTunes ID3 Tag v2.2 and lower did not load any id3 info.LAME3.90 v2.3 loaded twice,and MusicMatch v2.3 worked

  2. Al says:

    Reading the tags for artist name, track title, and other fields works fine, but for some reason, the genre returns “(31)” instead of “Trance”. Looked it up and apparently there are assigned number values for various “standardized” genres, and for some reason, Flash displays the number in parentheses instead of the actual genre. But if the genre entry in the MP3’s ID3 tag is changed to something like “abc123” or some other entry which does not match a typical genre name, the tag is read and displayed correctly.

    Any ideas? A Google search came up with nothing helpful…