Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Images, Sound, and Video > About loading and using external MP3 files > Reading ID3 tags in MP3 files | |||
ID3 tags are data fields that are added to an MP3 file. ID3 tags contain information about the file, such as the name of a song, album, and artist.
To read ID3 tags from an MP3 file, use the Sound.id3 property, whose properties correspond to the names of ID3 tags included in the MP3 file that you load. To determine when ID3 tags for a downloading MP3 file are available, use the Sound.onID3 event handler. Flash Player 7 supports version 1.0, 1.1, 2.3, and 2.4 tags; version 2.2 tags are not supported.
The following example loads an MP3 file named song1.mp3 into the song_sound Sound object. When the ID3 tags for the file are available, the display_txt text field shows the artist name and song name.
this.createTextField("display_txt", this.getNextHighestDepth(), 0, 0, 100, 100);
display_txt.autoSize = "left";
display_txt.multiline = true;
var song_sound:Sound = new Sound();
song_sound.onLoad = function() {
song_sound.start();
};
song_sound.onID3 = function():Void {
display_txt.text += "Artist:\t" + song_sound.id3.artist + "\n";
display_txt.text += "Song:\t" + song_sound.id3.songname + "\n";
};
song_sound.loadSound("http://www.helpexamples.com/flash/sound/song1.mp3");
The ID3 tags appear on the Stage, and the sound plays.
Because ID3 2.0 tags are located at the beginning of an MP3 file (before the sound data), they are available as soon as the file starts downloading. ID3 1.0 tags, however, are located at the end of the file (after the sound data), so they aren't available until the entire MP3 file finishes downloading.
The onID3 event handler is called each time new ID3 data is available. So, if an MP3 file contains ID3 2.0 tags and ID3 1.0 tags, the onID3 handler is called twice because the tags are located in different parts of the file.
For a list of supported ID3 tags, see id3 (Sound.id3 property) in the ActionScript 2.0 Language Reference.
For a sample source file that loads MP3 files, jukebox.fla, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ComponentsAS2/Jukebox folder to access this sample. This sample demonstrates how to create a jukebox by using data types, general coding principles, and several components.
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001030.html
Comments
meatlightning said on Mar 17, 2008 at 2:33 PM :