00:00
00:00
Newgrounds Background Image Theme

bugblast just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Id3 Tags 2007-04-06 19:22:11


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

Response to As: Id3 Tags 2007-04-06 19:26:54


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

Response to As: Id3 Tags 2007-04-06 19:30:33


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

Response to As: Id3 Tags 2007-04-06 19:46:54


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

Response to As: Id3 Tags 2007-04-06 23:00:47


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

Response to As: Id3 Tags 2007-04-14 16:21:01


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

Response to As: Id3 Tags 2007-06-18 04:09:26


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);
}


fuck yuo idiote

BBS Signature

Response to As: Id3 Tags 2008-01-26 08:34:23


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