Sound.id3 Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Sound.id3 Property Flash 6.0.40.0

access to the ID3 tags of an MP3 file read-only
soundObject.id3

Description

The id3 property is an object whose properties represent the ID3 tags of an MP3 sound file. MP3 files can be loaded into soundObject from a URL, via loadSound( ), or from the movie's Library via attachSound( ). The available id3 object properties are listed in Table 18-18. Note that Flash Player 6 supports ID3v1 and ID3v1.1 tags only.

Table 18-18. Sound.id3 object properties

Property

Description

album

The name of the album from which the song originates.

artist

The performer of the song.

comment

Arbitrary notes about the song.

genre

An integer that maps to a description of the song's musical style. For details, see Usage.

songname

The title of the song.

track

The number of the song on its album. (ID3v1.1 only)

year

The year the song was produced.

An MP3 file must be loaded in its entirety before its ID3 tags are available (ID3v1 and ID3v1.1 tags are stored at the end of an MP3 file). If the MP3 file does not contain valid ID3 tags in a version supported by the Flash Player, the id3 object's properties are undefined.

Usage

The ID3 "standard" is not an official specification maintained by a recognized standards body. Rather, it is an agreed-upon system for embedding metadata in an MP3 file; this system was created by a single programmer, Eric Kemp (who also assembled the first list of 80 genre names). Genre names above 80 are not formalized, nor is the entire genre system considered adequate by most music professionals. For one list of genres, see:

http://www.mp3dev.org/mp3/doc/html/id3.html

For more information on the ID3 format, see http://www.id3.org/.

Bugs

The id3 properties are not immediately available from Sound.onLoad( ). Use setInterval( ) to poll for a valid duration before accessing the id3 object, as shown in the following Example. (The id3 properties themselves will be undefined if no ID3 tags are found, so they cannot be polled reliably.)

Example

The following code loads an MP3 file and displays its ID3 tags once it has finished loading:

// REQUIRES FLASH PLAYER 6.0.40.0 OR HIGHER // Create a text field in which to display the ID3 information. this.createTextField("output_txt", 1, 100, 100, 400, 300); output_txt.border = true;     // Create a Sound object. song = new Sound(); // When the sound loads, display the ID3 information. song.onLoad = function (success) {   // Store a reference to the current sound.   var theSound = this;       // Create a function that displays the ID3 info once sound duration is valid.   function pollForDuration () {     if (theSound.duration > 0) {       // Display ID3 information.       output_txt.text += "Title:  " + theSound.id3.songname + "\n";       output_txt.text += "Artist: " + theSound.id3.artist + "\n";       output_txt.text += "Album:  " + theSound.id3.album + "\n";       output_txt.text += "Year:   " + theSound.id3.year + "\n";       output_txt.text += "Track:  " + theSound.id3.track + "\n";       output_txt.text += "Genre:  " + theSound.id3.genre + "\n";       output_txt.text += "Notes:  " + theSound.id3.comment + "\n";           // Play the sound.       theSound.start();           // Stop polling for a valid duration. This is required due to a       // bug: the id3 property is not immediately available from Sound.onLoad().       clearInterval(intID);     }   }       // If the sound loaded properly...   if (success =  = true) {     // ...repeatedly check for a valid duration.     var intID = setInterval(pollForDuration, 100);   } }     // Load the MP3 file song.loadSound("track1.mp3", false);

See Also

capabilities.hasMP3, Sound.loadSound( ), Sound.onLoad( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net