Be a Supporter!
Kart-Man
Kart-Man
  • Member since: Jan. 7, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
As: Id3 Tags 2007-04-06 19:22:11 Reply

AS: Main

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

BBS Signature
Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As: Id3 Tags 2007-04-06 19:26:54 Reply

Very nice tutorial, didn't know you could access id3 information in flash. Though, changing the order of the list to a more, order of more likely to use would have been an improvement.


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature
KaynSlamdyke
KaynSlamdyke
  • Member since: Jun. 25, 2004
  • Offline.
Forum Stats
Member
Level 16
Melancholy
Response to As: Id3 Tags 2007-04-06 19:30:33 Reply

At 4/6/07 07:22 PM, Kart-Man wrote: 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:

Definitely a required tute, and well written. Saw the id3 help in the help files about two weeks ago and wondered why no one had told me about it before. This has really filled a void. Congratulations


...

BBS Signature
Kart-Man
Kart-Man
  • Member since: Jan. 7, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to As: Id3 Tags 2007-04-06 19:46:54 Reply

At 4/6/07 07:25 PM, VictoryGin wrote: Very useful, though does it work with other formats? Not vital information, but good to know.

I'm not exactly sure what you mean by 'other formats', but if you mean programs, then yes. Media players (Windows Media Player, WinAmp, etc.) utilize id3 tags. How else can they display the song and artist data?

At 4/6/07 07:26 PM, Vengeance wrote: Very nice tutorial, didn't know you could access id3 information in flash. Though, changing the order of the list to a more, order of more likely to use would have been an improvement.

Yeah, now that I look at it, that probably would've helped (now people have to scroll up to view the list). Oh well.

At 4/6/07 07:30 PM, KaynSlamdyke wrote: Definitely a required tute, and well written. Saw the id3 help in the help files about two weeks ago and wondered why no one had told me about it before. This has really filled a void. Congratulations

Thanks. I've wondered for a while why there wasn't a section in AS: Main about id3 tags. It helps to sift through the Livedocs. You might learn some extra stuff. ;)


postcount +=1;
Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!
SING US A SING YOU'RE THE PIANO MAN

BBS Signature
Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to As: Id3 Tags 2007-04-06 23:00:47 Reply

At 4/6/07 07:46 PM, Kart-Man wrote:
At 4/6/07 07:25 PM, VictoryGin wrote: Very useful, though does it work with other formats? Not vital information, but good to know.
I'm not exactly sure what you mean by 'other formats', but if you mean programs, then yes. Media players (Windows Media Player, WinAmp, etc.) utilize id3 tags. How else can they display the song and artist data?

i think VictoryGin is asking if it works with other music formats, like WMA, WAV, and whatever. i don't think you can import WMA into flash, though. >_>


snyggys

DrRobot
DrRobot
  • Member since: Mar. 12, 2006
  • Offline.
Forum Stats
Member
Level 18
Game Developer
Response to As: Id3 Tags 2007-04-14 16:21:01 Reply

do you know how to get the TBPM or TLEN to work?

Sevkat
Sevkat
  • Member since: Dec. 31, 2006
  • Offline.
Forum Stats
Member
Level 29
Melancholy
Response to As: Id3 Tags 2007-06-18 04:09:26 Reply

Also, if you are wondering the script for a button that plays a song in your pc the code is:

on (press, release, rollover, etc.) {
mySound.loadSound("exampleSong.mp3",true);
}


==I LOVE YOU. EBOLA-CHAN! GOOD LUCK, EBOLA-CHAN! WE'RE ALL ROOTING FOR YOU, EBOLA-CHAN!==

BBS Signature
BrotherJohn
BrotherJohn
  • Member since: Sep. 13, 2007
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to As: Id3 Tags 2008-01-26 08:34:23 Reply

At 4/14/07 04:21 PM, DrRobot wrote: do you know how to get the TBPM or TLEN to work?

Are you trying to access tags without data? Of all of my MP3 files, none of them came equipped with a BPM value. The Lengths seem to work for me, though.

The tutorial table is very good to have posted. It is nice to see that here. The information I am having trouble finding is whether or not any "undocumented" support for non-UTF-8-encoded tags exists in ActionScript2.0. I have seen that table published in several places. All of the tables are identical. In the ActionScript 2.0 Dictionary (Macromedia Press) there is mention of tags that are accessible, but not published. In the Flash 8 help manual, the same table is available, but is accompanied by a note that explains that "only UTF-8 encoded tags are supported" and does not seem to include any additional tags. The ID3 website does not list the four-character reference names (that I could locate, anyway) and does not specify a full table of implementation.

The tag(s) I am trying to find support for in Flash (8, AS2.0) is the one that contains the album artwork. Is there a way to read this into a Flash script? If so, is there an additional tag that resides in ID3 that contains the information about that image, such as height, width, etc.? If not, I am sure the image would have its own metadata containing that information, but it would be much easier to work with if that was available in an ID3 tag. I may be searching for nothing here if Flash really does not support ANY non-UTF-8 encoded ID3 tags.

So, then, does AS3 support it? If so... looks like I'll be pinching pennies until I can afford the update.


BROTHER JOHN
Tone Matrix Productions Studios
© Brother John / Tone Matrix Productions Studios

BBS Signature