Thursday, August 4, 2011

How to access the information(id3 property)of the sound file

MP3 audio files are contain metadata about the sound file. This is most often used in music files to record the name of the song, the artist, album, genre, year of release, composer, etc. The information is actually included in these tags depends on who encoded or tagged the file. I think the most of the  cases though, you'll at least get the songname and artist tag.
So, to read the song's name, you would access it as follows:

_sound.id3.songName
The following example creates a text field and lists all available id3(information)of mp3 file tags:
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextField;

public class disp_ID3 extends Sprite {
private var _sound:Sound;

public function disp_ID3( ) {
_sound = new Sound(new URLRequest("song.mp3"));// the song name you want display the details
_sound.addEventListener(Event.ID3, onID3);
_sound.play( );
}

public function onID3(event:Event):void {
// Create a text field and display it
var id3Display:TextField = new TextField( );
addChild(id3Display);
id3Display.x = 10;
id3Display.y = 20;
id3Display.width = 200;
id3Display.height = 200;
id3Display.background = true;
id3Display.multiline = true;
id3Display.wordWrap = true;

// Add some info about the song to the text field
id3Display.text += _sound.id3.songName + "\n";
id3Display.text += _sound.id3.artist + "\n";
id3Display.text += _sound.id3.album + "\n";
id3Display.text += _sound.id3.year + "\n"; }
}
}
}

0 comments: