| How to Access MP3 ID3 Tag Data Using Sound Objects | Return to Index | Do you want all FLA's used for this tutorial? | Do you have a question? |
ID3 tag data refers to information that can be added to the MP3 file (using a variety of software) which can be displayed in your Flash player after the sound begins to load. The ID3 tags used in your Flash player are the same as those used in other non-Flash Players like Windows Media Player, WinAmp and MusicMatch Jukebox.
If ID3 tag data has been added to an MP3 file (don't assume it is there), it can be accessed when using the attachSound or loadSound methods by utilizing the id3 event handler.
Before Flash player version 6.r40, only ID3 tags 1.x are supported (specifically, 1.0 and 1.1). After which, ID3 tags 2.x are supported (specifically, 2.3 and 2.4 and not 2.2). One critical difference is that ID3 2.x store the ID3 tag data at the beginning of the MP3 file, versus at the end (as was true with ID3 1.x tags). This means that current Flash players do not need to wait for the MP3 to load completely before the ID3 tag data is available.
If you had a dynamic text box on stage with a variable name of "songArtist", you could update that dynamic text box with the artist information of your MP3 file using the following example:
mySound.loadSound("myCoolSong.MP3",true) mySound.onID3 = function () { |
In the above example, the sound object's name is "mySound". To access the ID3 data of mySound, you add the event handler ".id3" or ".ID3" (either will work), and the four letter code that represents the ID3 tag you want to access. The four-character ID3 code is always capitalized. In this case, the four-character code for the artist is TPE1.
The handler "onID3" is called into action when the ID3 data loads. This will either be at the beginning of the MP3 file (for ID3 v2.x) or at the end of the file for (ID3 v 1.x) or both. The above is placed as a non-looping frame action. Alternatively, the code could be placed in a looping event, such as an onClipEvent(enterFrame). Then, the text box would have been updated once the data was available. If the user is using the old version 6. r40 player, the entire MP3 must load before the onID3 handler will be able to supply the data to the dynamic text box.
Here is an example player that displays MP3 ID3 tag data. Special thanks to the band, gunderson, for this song, I'm Okay. Check out their website for more full songs you can hear at http://www.gundersonMusic.com.
| Fig. 27: Accessing MP3 ID3 tag data |
Tip : While nearly all media players, like MusicMatch Jukebox, offer a built-in tag editor, a good, free MP3 ID3 tag editor and viewer is MP3-Info Extension. It allows you to hover over the MP3 with your mouse curser and see the ID3 tag information. If you want to edit the ID3 tag information, you then can right-click the MP3, select properties, and there you will be able to edit the ID3 tag information. To obtain this free software, visit the following website:
http://www.mutschler.de/mp3ext
You need to decide if you are going to support Flash player v6.r40 and earlier. The Flash player v6.r40 was released in mid 2002. While we programmers like to think of people who use 2-year old players as luddites who are unworthy to see our masterful work, it is sometimes not the best approach. You can either force the user to upgrade to the current player, or write conditional code to deal with old players.
The 1.x ID3 tags were less arcane than the four-character 2.x tags. The 1.x ID3 tag for the artist would appear as "_root.mySoundObject.id3.artist". The follow table illustrates the various 2.x ID3 tags that are available.
| v2.x ID3 Tags | |||
|---|---|---|---|
| COMM | Comment | ||
| TALB | Album/movie/show title | ||
| TBPM | Beats per minute | ||
| TCOM | Composer | ||
| TCON | Content type | ||
| TCOP | Copyright message | ||
| TDAT | Date | ||
| TDLY | Playlist delay | ||
| TENC | Encoded by | ||
| TEXT | Lyricist/text writer | ||
| TFLT | File type | ||
| TIME | Time | ||
| TIT1 | Content group description | ||
| TIT2 | Title/song name/content description | ||
| TIT3 | Subtitle/description refinement | ||
| TKEY | Initial key | ||
| TLAN | Languages | ||
| TLEN | Length | ||
| TMED | Media type | ||
| TOAL | Original album/movie/show title | ||
| TOFN | Original filename | ||
| TOLY | Original lyricists/text writers | ||
| TOPE | Original artists/performers | ||
| TORY | Original release year | ||
| TOWN | File owner/licensee | ||
| TPE1 | Lead performers/soloists | ||
| TPE2 | Band/orchestra/accompaniment | ||
| TPE3 | Conductor/performer refinement | ||
| TPE4 | Interpreted, remixed, or otherwise modified by | ||
| TPOS | Part of a set | ||
| TPUB | Publisher | ||
| TRCK | Track number/position in set | ||
| TRDA | Recording dates | ||
| TRSN | Internet radio station name | ||
| TRSO | Internet radio station owner | ||
| TSIZ | Size | ||
| TSRC | ISRC (international standard recording code) | ||
| TSSE | Software/hardware and settings used for encoding | ||
| TYER | Year | ||
| WXXX | URL link frame | ||
|
|||
| COMM | Sound.id3.comment | ||
| TALB | Sound.id3.album | ||
| TCON | Sound.id3.genre | ||
| TIT2 | Sound.id3.songname | ||
| TPE1 | Sound.id3.artist | ||
| TRCK | Sound.id3.track | ||
| TYER | Sound.id3.year | ||
If the MP3 file contains ID3 1.x tags and ID3 2.x tags (which is common), and the user has a Flash player version 6 (the 2-year old player), calls to display ID3 2.x tags would result in "undefined".
If you want to see what ID3 tags are populated with data, you can trace the ID3 information that is available in a MP3 file using the following example:
mySound.loadSound("myCoolSong.MP3",true) mySound.onID3 = function () { |
After seeing the results from that trace, you will know if you need to use a ID3 tag editor to add additional data to the MP3 file.
This document copyright © 2004 by Kenny Bellew of Cowfly.Com Design, kennybellew@hotmail.com