JID3 - A JavaTM ID3 Class Library Implementation

Copyright 2003-2005 Paul Grebenc

JID3 is a class library, written in Java and licensed under the LGPL, which provides the required functionality for editing ID3 tags commonly used in MP3 media files.


A quick sample, writing both v1.0 and v2.3.0 tags to an MP3 file:


package id3test;

import java.io.*;
import org.blinkenlights.jid3.*;
import org.blinkenlights.jid3.v1.*;
import org.blinkenlights.jid3.v2.*;

public class ID3Test
{
    private static void main(String[] args)
        throws Exception
    {
        // the file we are going to modify
        File oSourceFile = new File("some_file.mp3");

        // create an MP3File object representing our chosen file
        MediaFile oMediaFile = new MP3File(oSourceFile);

        // create a v1.0 tag object, and set some values
        ID3V1_0Tag oID3V1_0Tag = new ID3V1_0Tag();
        oID3V1_0Tag.setAlbum("Album");
        oID3V1_0Tag.setArtist("Artist");
        oID3V1_0Tag.setComment("Comment");
        oID3V1_0Tag.setGenre(ID3V1Tag.Genre.Blues);
        oID3V1_0Tag.setTitle("Title");
        oID3V1_0Tag.setYear("1999");
       
        // set this v1.0 tag in the media file object
        oMediaFile.setID3Tag(oID3V1_0Tag);
       
        // create a v2.3.0 tag object, and set some frames
        ID3V2_3_0Tag oID3V2_3_0Tag = new ID3V2_3_0Tag();
        TPE1TextInformationID3V2Frame oTPE1 = new TPE1TextInformationID3V2Frame("Lead Performer");
        oID3V2_3_0Tag.setTPE1TextInformationFrame(oTPE1);
        TRCKTextInformationID3V2Frame oTRCK = new TRCKTextInformationID3V2Frame(3, 9);
        oID3V2_3_0Tag.setTRCKTextInformationFrame(oTRCK);
        TIT2TextInformationID3V2Frame oTIT2 = new TIT2TextInformationID3V2Frame("Song Title");
        oID3V2_3_0Tag.setTIT2TextInformationFrame(oTIT2);
       
        // set this v2.3.0 tag in the media file object
        oMediaFile.setID3Tag(oID3V2_3_0Tag);
       
        // update the actual file to reflect the current state of our object 
        oMediaFile.sync();
    }
}

Another sample, writing v2.3.0 tags to an MP3 file, using the convenience methods (convenience methods are only available for frames that map to V1.1 settings, which seem to be all many people care about):


package id3test;

import java.io.*;
import org.blinkenlights.jid3.*;
import org.blinkenlights.jid3.v2.*;

public class ID3Test
{
    private static void main(String[] args)
        throws Exception
    {
        // the file we are going to modify
        File oSourceFile = new File("some_file.mp3");

        // create an MP3File object representing our chosen file
        MediaFile oMediaFile = new MP3File(oSourceFile);

        // create a v2.3.0 tag object, and set values using convenience methods
        ID3V2_3_0Tag oID3V2_3_0Tag = new ID3V2_3_0Tag();
        oID3V2_3_0Tag.setAlbum("Album");  // sets TALB frame
        oID3V2_3_0Tag.setArtist("Artist");  // sets TPE1 frame
        oID3V2_3_0Tag.setComment("Comment");  // sets COMM frame with language "eng" and no description
        oID3V2_3_0Tag.setGenre("Blues");  // sets TCON frame
        oID3V2_3_0Tag.setTitle("Title");  // sets TIT2 frame
        oID3V2_3_0Tag.setYear(1999);  // sets TYER frame
       
        // set this v2.3.0 tag in the media file object
        oMediaFile.setID3Tag(oID3V2_3_0Tag);
       
        // update the actual file to reflect the current state of our object 
        oMediaFile.sync();
    }
}

A sample reading tags from an MP3 file, specifically looking for certain properties in v1.0 and v2.3.0 tags:


package id3test;

import java.io.*;
import org.blinkenlights.jid3.*;
import org.blinkenlights.jid3.v1.*;
import org.blinkenlights.jid3.v2.*;

public class ID3Test
{
    private static void main(String[] args)
        throws Exception
    {
        // the file we are going to read
        File oSourceFile = new File("some_file.mp3");

        // create an MP3File object representing our chosen file
        MediaFile oMediaFile = new MP3File(oSourceFile);

        // any tags read from the file are returned, in an array, in an order which you should not assume
        ID3Tag[] aoID3Tag = oMediaFile.getTags();
        // let's loop through and see what we've got
        // (NOTE:  we could also use getID3V1Tag() or getID3V2Tag() methods, if we specifically want one or the other)
        for (int i=0; i < aoID3Tag.length; i++)
        {
            // check to see if we read a v1.0 tag, or a v2.3.0 tag (just for example..)
            if (aoID3Tag[i] instanceof ID3V1_0Tag)
            {
                ID3V1_0Tag oID3V1_0Tag = (ID3V1_0Tag)aoID3Tag[i];
                // does this tag happen to contain a title?
                if (oID3V1_0Tag.getTitle() != null)
                {
                    System.out.println("Title = " + oID3V1_0Tag.getTitle());
                }
                // etc.
            }
            else if (aoID3Tag[i] instanceof ID3V2_3_0Tag)
            {
                ID3V2_3_0Tag oID3V2_3_0Tag = (ID3V2_3_0Tag)aoID3Tag[i];
                // check if this v2.3.0 frame contains a title, using the actual frame name
                if (oID3V2_3_0Tag.getTIT2TextInformationFrame() != null)
                {
                    System.out.println("Title = " + oID3V2_3_0Tag.getTIT2TextInformationFrame().getTitle());
                }
                // but check using the convenience method if it has a year set (either way works)
                try
                {
                    System.out.println("Year = " + oID3V2_3_0Tag.getYear());  // reads TYER frame
                }
                catch (ID3Exception e)
                {
                    // error getting year.. if one wasn't set
                    System.out.println("Could get read year from tag: " + e.toString());
                }
                // etc.
            }
        }
    }
}

Until proper documentation is written, your best bet for further details is to have a look at the javadocs, and at the test suites, to see how the library is used.


Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems,Inc. in the United States and other countries.

BACK