«« Two Tiered Approach for a Library Automatic Object Test Generation »»
blog header image
jid3rL Wrapped in SimpleTag2

Ironically enough, after blogging about how the full jid3rL library might be "a bit much for general use", I ran into that problem integrating jid3rL into AudioMan. It was just a lot more than I needed.

I thought about the easiest way it could be presented if the user only needed to read/modify/create a few basic frame types from/in an MP3 file. I made a class called SimpleTag2 which wraps around a full Tag2 object and has only a few methods:

public SimpleTag2(Version version) //constructor
protected SimpleTag2(Tag2 tag) // constructor only used by parse()

public String get(SimpleFrameId id)
public void set(SimpleFrameId id, String value)

public static SimpleTag2 parse(File f) throws IOException
public void writeToFile(File f) throws IOException

The SimpleFrameId is another one of those Java enumeration classes, and contains a few of the popular frame ids abstracted out:

TRACK_NAME
ARTIST_NAME
ALBUM_NAME
GENRE
YEAR
COMMENTS
TRACK_NUMBER

Then if you want to read a file's tag, it looks like this:

File f = new File("soundgarden - superunknown.mp3");
SimpleTag2 tag = SimpleTag2.parse(f);

System.out.println("track name: " + tag.get(SimpleFrameId.TRACK_NAME));

You can modify that file by continuing...

tag.set(SimpleFrameId.TRACK_NAME, "Superunknown");
tag.writeToFile(f);

You can also create a tag from scratch and write it to any file:

SimpleTag2 tag = new SimpleTag2(Version.v2_3);
tag.set(SimpleFrameId.TRACK_NAME, "Transatlanticism");
tag.set(SimpleFrameId.ARTIST_NAME, "Death Cab for Cutie");

File f = new File("trans.mp3");
tag.writeToFile(f);

In exchange for a powerful API, you get something that's pretty easy to use and extensible. Thoughts?

Posted at August 17, 2004 at 10:22 AM EST
Last updated August 17, 2004 at 10:22 AM EST
Comments

Looks good so far!

» Posted by: roy at August 17, 2004 10:52 AM
Google
 
Search scope: Web ryanlowe.ca