org.farng.mp3.id3
Class ID3v1

java.lang.Object
  extended by org.farng.mp3.AbstractMP3FileItem
      extended by org.farng.mp3.AbstractMP3Tag
          extended by org.farng.mp3.id3.AbstractID3
              extended by org.farng.mp3.id3.AbstractID3v1
                  extended by org.farng.mp3.id3.ID3v1
All Implemented Interfaces:
MP3Tag
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: 3 $
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()
          Get the song's album title.
 java.lang.String getArtist()
           
 java.lang.String getAuthorComposer()
          Get the author/composer.
 java.lang.String getComment()
           
 byte getGenre()
           
 ID3v1 getID3tag(java.io.RandomAccessFile file)
           
 java.lang.String getIdentifier()
           
 java.lang.String getLeadArtist()
          Get the lead artist.
 int getSize()
           
 java.lang.String getSongComment()
          Get a song comment.
 java.lang.String getSongGenre()
          Get the genre.
 java.lang.String getSongLyric()
          Get the song lyrics.
 java.lang.String getSongTitle()
          Get the song title.
 java.lang.String getTitle()
           
 java.lang.String getTrackNumberOnAlbum()
          Get the track number.
 java.lang.String getYear()
           
 java.lang.String getYearReleased()
          Get the year the song was released.
 java.util.Iterator iterator()
          Get an iterator over all tags available.
 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.

Throws:
TagNotFoundException
java.io.IOException
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()
Specified by:
getIdentifier in class AbstractMP3FileItem

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
Parameters:
obj - object to determine equality of
Returns:
true if this object and its body are equal

iterator

public java.util.Iterator iterator()
Description copied from interface: MP3Tag
Get an iterator over all tags available.

Returns:
iterator

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()
Overrides:
toString in class java.lang.Object

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()
Description copied from interface: MP3Tag
Get the song title.

Returns:
song title

getLeadArtist

public java.lang.String getLeadArtist()
Description copied from interface: MP3Tag
Get the lead artist.

Returns:
lead artist

getAlbumTitle

public java.lang.String getAlbumTitle()
Description copied from interface: MP3Tag
Get the song's album title.

Returns:
album title

getYearReleased

public java.lang.String getYearReleased()
Description copied from interface: MP3Tag
Get the year the song was released.

Returns:
year

getSongComment

public java.lang.String getSongComment()
Description copied from interface: MP3Tag
Get a song comment.

Returns:
comment

getSongGenre

public java.lang.String getSongGenre()
Description copied from interface: MP3Tag
Get the genre.

Returns:
genre

getTrackNumberOnAlbum

public java.lang.String getTrackNumberOnAlbum()
Description copied from interface: MP3Tag
Get the track number.

Returns:
track number

getSongLyric

public java.lang.String getSongLyric()
Description copied from interface: MP3Tag
Get the song lyrics.

Returns:
song lyrics

getAuthorComposer

public java.lang.String getAuthorComposer()
Description copied from interface: MP3Tag
Get the author/composer.

Returns:
author/composer

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