View comments | RSS feed

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.

To read ID3 tags from an MP3 file:

  1. Create a new FLA file called id3.fla.
  2. Select Frame 1 on the Timeline and type the following code in the Actions panel:
    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");
    
  3. Select Control > Test Movie to test the sound.

    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


Comments


meatlightning said on Mar 17, 2008 at 2:33 PM :
doesnt' work.

1046: Type was not found or was not a compile-time constant: Void. song_sound.onID3 = function():Void {
adbe_paul said on Mar 20, 2008 at 11:35 AM :
@meatlightn:

I'm not sure if this is your issue, but my first guess is that you're using this with the ActionScript version set to ActionScript 3.0 rather than ActionScript 2.0.

In ActionScript 3.0 the capitalization changed, so it's "void" instead of "Void".
tinyrobot said on Apr 5, 2008 at 4:06 AM :
this is AS2 documentation in an AS3 header. It even references the AS2 Language reference at the bottom.

 

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