{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}
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
( )