Working with sound metadata

Sound files that use the MP3 format can contain additional data about the sound in the form of ID3 tags.

Not every MP3 file contains ID3 metadata. When a Sound object loads an MP3 sound file, it dispatches an Event.ID3 event if the sound file contains ID3 metadata. To prevent run-time errors, your application should wait to receive the Event.ID3 event before accessing the Sound.id3 property for a loaded sound.

The following code shows how to recognize when the ID3 metadata for a sound file has been loaded:

var s = new air.Sound(); 
s.addEventListener(air.Event.ID3, onID3InfoReceived); 
var urlReq = new air.URLRequest("mySound.mp3"); 
s.load(urlReq); 
 
function onID3InfoReceived(event) 
{ 
    var id3 = event.target.id3; 
 
    air.trace("Received ID3 Info:"); 
    for (propName in id3) 
    { 
        air.trace(propName + " = " + id3[propName]); 
    } 
}

This code starts by creating a Sound object and telling it to listen for the id3 event. When the sound file’s ID3 metadata is loaded, the onID3InfoReceived() method is called. The target of the Event object that is passed to the onID3InfoReceived() method is the original Sound object. The method then gets the Sound object’s id3 property and iterates through its named properties to trace their values.