Lemieux Design

Flash | Interactive | Web | Graphics | Brand | Video

Archive for January, 2009

Flash AS3 MP3 Player with XML

Posted on: January 30th, 2009 by alemieux

I’m working on an XML-based MP3 player in AS3 and there are so many things to think about here. For example, AS3 allows you to read ID3 tags from MP3 files. But I found out with a lot of testing, that it doesn’t read all ID3 tags. In my case, I gave it a bunch of different MP3 files and it didn’t read anything.

Here’s the code:

var url:String = “Falling Down.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);
textArea.text += “album” + “:\t” + song.id3.album + “\n”;
textArea.text += “artist” + “:\t” + song.id3.artist + “\n”;
textArea.text += “comment” + “:\t” + song.id3.comment + “\n”;
textArea.text += “genre” + “:\t” + song.id3.genre + “\n”;
textArea.text += “songName” + “:\t” + song.id3.songName + “\n”;
textArea.text += “track” + “:\t” + song.id3.track + “\n”;
textArea.text += “year” + “:\t” + song.id3.year + “\n”;
textArea.text += “———————————”;
}

No luck with this. Anyone else have a problem with ID3? I think a more common practice is to get the info from an XML file. The problem with that is now you have to continuously update or change the XML file.

Anyhow, let me know what you think.