Ever wondered how to dynamically display the song title or artist of a song (well, okay, probably not, but still...)? Ever tried loading a bunch of songs via Actionscript, then trying to make a stupid-looking music player out of it, to no avail? If so, then it looks like you have never heard of the ID3 tag.
Take a look at an mp3. It's one of the most popular formats for storing and playing ditigal music, as it has good compression, a low file size, and has really high quality. Mp3s also carry around metadata, which is descriptive information about the song file's data. In other words, people can read the ID3 tag that the metadata is stored in and easily view the mp3 file's song title, artist, album, and other bits of data (which is essentially how music players like Windows Media Player work).
Flash can read the ID3 tag (now at version 2) of an mp3 file. Each bit of data in the ID3 tag corresponds to a property in the Sound object. Here is a list of the sound properties:
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
To use these, add id3. before them.
---
Okay, let's write out some code. Open up an empty Flash document, and make a dynamic text box with the variable name 'songArtist'. type in this:
var mySound:Sound = new Sound();
mySound.loadSound("exampleSong.mp3",true);
mySound.onID3 = function () {
trace("Artist:"+mySound.id3.TPE1);
}
This will trace the artist of the mp3 if you press Ctrl + Enter. Now, let's take a look at the code:
var mySound:Sound = new Sound();
This declares a variable, mySound, as a Sound object.
mySound.loadSound("exampleSong.mp3",true);
LoadSound() streams the mp3 file "exampleSong.mp3", which resides in the same directory as your Flash movie. Type in the correct target path here.
mySound.onID3 = function () {
trace("Artist:"+mySound.id3.TPE1);
}
The onID3 handler is attached to the mySound Sound object we had earlier. The handler is triggered when there is ID3 data in the mp3. We then use the trace(); statement to trace the artist of the song (hence the TPE1).
Save your .fla file in the location where it can find your mp3 file based on the target path you entered (which should be in the same folder as your mp3 file). When you test your movie, the Output panel should pop up with the word 'Artist:', followed by the artist name.
Troubleshooting:
- Save your Flash file.
- Make sure that you typed in the mp3's target path correctly.
- Make sure that the ID3 Sound property is typed in correctly (stupid mistakes can happen!)
- Make sure you typed the code correctly (no syntax errors).
Go easy on me; this is my first AS: Main tutorial. If I've made any mistakes, or if there's some extra information, just post. Thanks. :)
Extra Reading:
Flash Livedocs - Sound.id3
postcount +=1;
Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!
SING US A SING YOU'RE THE PIANO MAN
