org.farng.mp3.id3
Class ID3v1

java.lang.Object
  extended byorg.farng.mp3.AbstractMP3FileItem
      extended byorg.farng.mp3.AbstractMP3Tag
          extended byorg.farng.mp3.id3.AbstractID3
              extended byorg.farng.mp3.id3.AbstractID3v1
                  extended byorg.farng.mp3.id3.ID3v1
Direct Known Subclasses:
ID3v1_1

public class ID3v1
extends AbstractID3v1

What is ID3 (v1)?

The audio format MPEG layer I, layer II and layer III (MP3) has no native way of saving information about the contents, except for some simple yes/no parameters like "private", "copyrighted" and "original home" (meaning this is the original file and not a copy). A solution to this problem was introduced with the program "Studio3" by Eric Kemp alias NamkraD in 1996. By adding a small chunk of extra data in the end of the file one could get the MP3 file to carry information about the audio and not just the audio itself.

The placement of the tag, as the data was called, was probably chosen as there were little chance that it should disturb decoders. In order to make it easy to detect a fixed size of 128 bytes was chosen. The tag has the following layout (as hinted by the scheme to the right):

Song title 30 characters
Artist 30 characters
Album 30 characters
Year 4 characters
Comment 30 characters
Genre 1 byte

If you one sum the the size of all these fields we see that 30+30+30+4+30+1 equals 125 bytes and not 128 bytes. The missing three bytes can be found at the very end of the tag, before the song title. These three bytes are always "TAG" and is the identification that this is indeed a ID3 tag. The easiest way to find a ID3v1/1.1 tag is to look for the word "TAG" 128 bytes from the end of a file.

As all artists doesn't have a 30 character name it is said that if there is some bytes left after the information is entered in the field, those bytes should be fille with the binary value 0. You might also think that you cannot write that much in the genre field, being one byte big, but it is more clever than that. The byte value you enter in the genre field corresponds to a value in a predefined list. The list that Eric Kemp created had 80 entries, ranging from 0 to 79.

Version:
$Revision: 1.6 $
Author:
Eric Farng

Field Summary
protected  java.lang.String album
           
protected  java.lang.String artist
           
protected  java.lang.String comment
           
protected  byte genre
           
protected  java.lang.String title
           
protected  java.lang.String year
           
 
Constructor Summary
ID3v1()
          Creates a new ID3v1 object.
ID3v1(AbstractMP3Tag mp3tag)
          Creates a new ID3v1 object.
ID3v1(ID3v1 copyObject)
          Creates a new ID3v1 object.
ID3v1(java.io.RandomAccessFile file)
          Creates a new ID3v1 object.
 
Method Summary
 void append(AbstractMP3Tag tag)
          This method does nothing, but is called by subclasses for completeness
 void delete(java.io.RandomAccessFile file)
          removes the specific tag the easiest way.
 boolean equals(java.lang.Object obj)
          Determines whether another object is equal to this tag.
 java.lang.String getAlbum()
           
 java.lang.String getAlbumTitle()
           
 java.lang.String getArtist()
           
 java.lang.String getAuthorComposer()
           
 java.lang.String getComment()
           
 byte getGenre()
           
 ID3v1 getID3tag(java.io.RandomAccessFile file)
           
 java.lang.String getIdentifier()
          ID string that usually corresponds to the class name, but can be displayed to the user.
 java.lang.String getLeadArtist()
           
 int getSize()
           
 java.lang.String getSongComment()
           
 java.lang.String getSongGenre()
           
 java.lang.String getSongLyric()
           
 java.lang.String getSongTitle()
           
 java.lang.String getTitle()
           
 java.lang.String getTrackNumberOnAlbum()
           
 java.lang.String getYear()
           
 java.lang.String getYearReleased()
           
 java.util.Iterator iterator()
           
 void overwrite(AbstractMP3Tag tag)
          This method does nothing, but is called by subclasses for completeness
 void read(java.io.RandomAccessFile file)
          import java.io.IOException; import java.io.RandomAccessFile; read from current file pointer position.
 boolean seek(java.io.RandomAccessFile file)
          Looks for this tag.
 void setAlbum(java.lang.String album)
           
 void setAlbumTitle(java.lang.String albumTitle)
           
 void setArtist(java.lang.String artist)
           
 void setAuthorComposer(java.lang.String authorComposer)
           
 void setComment(java.lang.String comment)
           
 void setGenre(byte genre)
           
 void setLeadArtist(java.lang.String leadArtist)
           
 void setSongComment(java.lang.String songComment)
           
 void setSongGenre(java.lang.String songGenre)
           
 void setSongLyric(java.lang.String songLyrics)
           
 void setSongTitle(java.lang.String songTitle)
           
 void setTitle(java.lang.String title)
           
 void setTrackNumberOnAlbum(java.lang.String trackNumberOnAlbum)
           
 void setYear(java.lang.String year)
           
 void setYearReleased(java.lang.String yearReleased)
           
 java.lang.String toString()
           
 void write(AbstractMP3Tag tag)
          This method does nothing, but is called by subclasses for completeness
 void write(java.io.RandomAccessFile file)
          Method to write this object to the file argument at is current file pointer position.
 
Methods inherited from class org.farng.mp3.id3.AbstractID3v1
append, overwrite
 
Methods inherited from class org.farng.mp3.AbstractMP3Tag
isSubsetOf
 
Methods inherited from class org.farng.mp3.AbstractMP3FileItem
isSubsetOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

album

protected java.lang.String album

artist

protected java.lang.String artist

comment

protected java.lang.String comment

title

protected java.lang.String title

year

protected java.lang.String year

genre

protected byte genre
Constructor Detail

ID3v1

public ID3v1()
Creates a new ID3v1 object.


ID3v1

public ID3v1(ID3v1 copyObject)
Creates a new ID3v1 object.


ID3v1

public ID3v1(AbstractMP3Tag mp3tag)
Creates a new ID3v1 object.


ID3v1

public ID3v1(java.io.RandomAccessFile file)
      throws TagNotFoundException,
             java.io.IOException
Creates a new ID3v1 object.

Method Detail

setAlbum

public void setAlbum(java.lang.String album)

getAlbum

public java.lang.String getAlbum()

setArtist

public void setArtist(java.lang.String artist)

getArtist

public java.lang.String getArtist()

setComment

public void setComment(java.lang.String comment)

getComment

public java.lang.String getComment()

setGenre

public void setGenre(byte genre)

getGenre

public byte getGenre()

getID3tag

public ID3v1 getID3tag(java.io.RandomAccessFile file)
                throws java.io.IOException
Throws:
java.io.IOException

getIdentifier

public java.lang.String getIdentifier()
Description copied from class: AbstractMP3FileItem
ID string that usually corresponds to the class name, but can be displayed to the user. It is not indended to identify each individual instance.

Specified by:
getIdentifier in class AbstractMP3FileItem
Returns:
ID string

getSize

public int getSize()
Specified by:
getSize in class AbstractMP3FileItem

setTitle

public void setTitle(java.lang.String title)

getTitle

public java.lang.String getTitle()

setYear

public void setYear(java.lang.String year)

getYear

public java.lang.String getYear()

append

public void append(AbstractMP3Tag tag)
Description copied from class: AbstractMP3Tag
This method does nothing, but is called by subclasses for completeness

Specified by:
append in class AbstractMP3Tag
Parameters:
tag - tag to overwrite

delete

public void delete(java.io.RandomAccessFile file)
            throws java.io.IOException
Description copied from class: AbstractMP3Tag
removes the specific tag the easiest way.
ID3v1 - cuts the length of the tag
lyrics3 -cuts the length of the tag, then writes the id3v1 tag if it existed
id3v2 - just overwrites the ID3 tag indicator at the start of the tag

Specified by:
delete in class AbstractMP3Tag
Parameters:
file - MP3 file to append to.
Throws:
java.io.IOException - on any I/O error

equals

public boolean equals(java.lang.Object obj)
Description copied from class: AbstractMP3Tag
Determines whether another object is equal to this tag. It just compares if they are the same class, then calls super.equals(object).

Overrides:
equals in class AbstractMP3Tag

iterator

public java.util.Iterator iterator()
Specified by:
iterator in class AbstractMP3Tag

overwrite

public void overwrite(AbstractMP3Tag tag)
Description copied from class: AbstractMP3Tag
This method does nothing, but is called by subclasses for completeness

Specified by:
overwrite in class AbstractMP3Tag
Parameters:
tag - tag to overwrite

read

public void read(java.io.RandomAccessFile file)
          throws TagNotFoundException,
                 java.io.IOException
Description copied from class: AbstractMP3FileItem
import java.io.IOException; import java.io.RandomAccessFile; read from current file pointer position.

Specified by:
read in class AbstractMP3FileItem
Parameters:
file - file to read from
Throws:
java.io.IOException - on any I/O error
TagNotFoundException

seek

public boolean seek(java.io.RandomAccessFile file)
             throws java.io.IOException
Description copied from class: AbstractMP3Tag
Looks for this tag. returns true if found. If found, the file pointer is right after the tag start indicator i.e. "TAG" "LYRICSBEGIN" "ID3" + 2

Specified by:
seek in class AbstractMP3Tag
Parameters:
file - MP3 file to overwrite
Returns:
returns true if found, false otherwise.
Throws:
java.io.IOException - on any I/O error

toString

public java.lang.String toString()

write

public void write(AbstractMP3Tag tag)
Description copied from class: AbstractMP3Tag
This method does nothing, but is called by subclasses for completeness

Specified by:
write in class AbstractMP3Tag
Parameters:
tag - tag to write to

write

public void write(java.io.RandomAccessFile file)
           throws java.io.IOException
Description copied from class: AbstractMP3FileItem
Method to write this object to the file argument at is current file pointer position.

Specified by:
write in class AbstractMP3FileItem
Parameters:
file - file to write to
Throws:
java.io.IOException - on any I/O error

getSongTitle

public java.lang.String getSongTitle()
Specified by:
getSongTitle in class AbstractMP3Tag

getLeadArtist

public java.lang.String getLeadArtist()
Specified by:
getLeadArtist in class AbstractMP3Tag

getAlbumTitle

public java.lang.String getAlbumTitle()
Specified by:
getAlbumTitle in class AbstractMP3Tag

getYearReleased

public java.lang.String getYearReleased()
Specified by:
getYearReleased in class AbstractMP3Tag

getSongComment

public java.lang.String getSongComment()
Specified by:
getSongComment in class AbstractMP3Tag

getSongGenre

public java.lang.String getSongGenre()
Specified by:
getSongGenre in class AbstractMP3Tag

getTrackNumberOnAlbum

public java.lang.String getTrackNumberOnAlbum()
Specified by:
getTrackNumberOnAlbum in class AbstractMP3Tag

getSongLyric

public java.lang.String getSongLyric()
Specified by:
getSongLyric in class AbstractMP3Tag

getAuthorComposer

public java.lang.String getAuthorComposer()
Specified by:
getAuthorComposer in class AbstractMP3Tag

setSongTitle

public void setSongTitle(java.lang.String songTitle)
Specified by:
setSongTitle in class AbstractMP3Tag

setLeadArtist

public void setLeadArtist(java.lang.String leadArtist)
Specified by:
setLeadArtist in class AbstractMP3Tag

setAlbumTitle

public void setAlbumTitle(java.lang.String albumTitle)
Specified by:
setAlbumTitle in class AbstractMP3Tag

setYearReleased

public void setYearReleased(java.lang.String yearReleased)
Specified by:
setYearReleased in class AbstractMP3Tag

setSongComment

public void setSongComment(java.lang.String songComment)
Specified by:
setSongComment in class AbstractMP3Tag

setSongGenre

public void setSongGenre(java.lang.String songGenre)
Specified by:
setSongGenre in class AbstractMP3Tag

setTrackNumberOnAlbum

public void setTrackNumberOnAlbum(java.lang.String trackNumberOnAlbum)
Specified by:
setTrackNumberOnAlbum in class AbstractMP3Tag

setSongLyric

public void setSongLyric(java.lang.String songLyrics)
Specified by:
setSongLyric in class AbstractMP3Tag

setAuthorComposer

public void setAuthorComposer(java.lang.String authorComposer)
Specified by:
setAuthorComposer in class AbstractMP3Tag


Copyright (c) 2004 Eric Farng