Not yet rated

Problem

You are creating a mobile mp3 player and would like to display some of the metadata about the song currently playing.

Solution

You can read the id3Info property of the Sound object.

Detailed explanation

After selecting an mp3 file using the File.browse method and passing in a FileFilter to limit the selection to mp3 as shown in the recipe  Using FileFilter in Android Mobile, be sure to add an event listener to listen for Event.ID3 on the Sound object. Here is a snippet of the method that is called after a user selects a file.

private function onFileSelect(event:Event):void{
    file.removeEventListener(Event.SELECT, onFileSelect);
    file = File(event.currentTarget);
    sound = new Sound();    
    sound.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
    sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    sound.addEventListener(Event.ID3,showID3);
    sound.addEventListener(Event.COMPLETE, loadComplete);
    sound.load(new URLRequest(file.url));    
}

When the ID3 info is available, the showID3 method is called. Within this method the sound's id3 properties are read as shown below. These include the id3.album, id3.artist, id3.genre, id3.songName, id3.track, and id3.year. The results can be seen in the screen shot below.

private function showID3(event:Event):void {    
trace("Album: " + sound.id3.album);
trace("Artist: " + sound.id3.artist);
trace("Genre: " + sound.id3.genre);
trace("Songname: " + sound.id3.songName);
trace("Track: " + sound.id3.track);
trace("Year: " + sound.id3.year);
}

 

You are creating a mobile mp3 player and would like to display some of the metadata about the song currently playing.

 

Please consider purchasing Developing Android Applications with Flex 4.5.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes