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);
}
Comments
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
Posted by: Steve | February 15, 2008 11:53 AM