org.jaudiotagger.audio.mp3
Class MP3File

java.lang.Object
  extended by org.jaudiotagger.audio.AudioFile
      extended by org.jaudiotagger.audio.mp3.MP3File

public class MP3File
extends AudioFile

This class represents a physical MP3 File


Field Summary
private  ID3v1Tag id3v1tag
          The ID3v1 tag that this file contains.
private  ID3v24Tag id3v2Asv24tag
          Representation of the idv2 tag as a idv24 tag
private  AbstractID3v2Tag id3v2tag
          the ID3v2 tag that this file contains.
static int LOAD_ALL
           
static int LOAD_IDV1TAG
           
static int LOAD_IDV2TAG
           
static int LOAD_LYRICS3
          This option is currently ignored
private  AbstractLyrics3 lyrics3tag
          The Lyrics3 tag that this file contains.
private static int MINIMUM_FILESIZE
           
protected static AbstractTagDisplayFormatter tagFormatter
           
 
Fields inherited from class org.jaudiotagger.audio.AudioFile
audioHeader, file, logger, tag
 
Constructor Summary
MP3File()
          Creates a new empty MP3File datatype that is not associated with a specific file.
MP3File(java.io.File file)
          Creates a new MP3File datatype and parse the tag from the given file Object.
MP3File(java.io.File file, int loadOptions)
          Creates a new MP3File datatype and parse the tag from the given file Object, files must be writable to use this constructor.
MP3File(java.io.File file, int loadOptions, boolean readOnly)
          Creates a new MP3File datatype and parse the tag from the given file Object, files can be onpened read only if required.
MP3File(java.lang.String filename)
          Creates a new MP3File datatype and parse the tag from the given filename.
 
Method Summary
private  MP3AudioHeader checkAudioStart(long startByte, MP3AudioHeader currentHeader)
          Regets the audio header starting from start of file, and write appropriate logging to indicate potential problem to user.
 void commit()
          Overriden for comptability with merged code
 Tag createDefaultTag()
          Create Default Tag
private static void createPlainTextStructureFormatter()
           
private static void createXMLStructureFormatter()
           
 void delete(AbstractTag mp3tag)
          Remove tag from file
 java.lang.String displayStructureAsPlainText()
          Displays MP3File Structure
 java.lang.String displayStructureAsXML()
          Displays MP3File Structure
 java.io.File extractID3v2TagDataIntoFile(java.io.File outputFile)
          Extracts the raw ID3v2 tag data into a file.
 ID3v1Tag getID3v1Tag()
          Returns the ID3v1 tag for this datatype.
 AbstractID3v2Tag getID3v2Tag()
          Returns the ID3v2 tag for this datatype.
 ID3v24Tag getID3v2TagAsv24()
           
 MP3AudioHeader getMP3AudioHeader()
          Return audio header
 long getMP3StartByte(java.io.File file)
          Used by tags when writing to calculate the location of the music file
static AbstractTagDisplayFormatter getStructureFormatter()
           
 boolean hasID3v1Tag()
          Returns true if this datatype contains an Id3v1 tag
 boolean hasID3v2Tag()
          Returns true if this datatype contains an Id3v2 tag
 void precheck(java.io.File file)
          Check can write to file
private  void readLyrics3Tag(java.io.File file, java.io.RandomAccessFile newFile, int loadOptions)
          Read lyrics3 Tag

TODO:not working

private  void readV1Tag(java.io.File file, java.io.RandomAccessFile newFile, int loadOptions)
          Read v1 tag
private  void readV2Tag(java.io.File file, int loadOptions)
          Read V2tag if exists

TODO:shouldnt we be handing TagExceptions:when will they be thrown

 void save()
          Saves the tags in this datatype to the file referred to by this datatype.
 void save(java.io.File file)
          Saves the tags in this datatype to the file argument.
 void setID3v1Tag(AbstractTag mp3tag)
          Sets the ID3v1 tag for this datatype.
 void setID3v1Tag(ID3v1Tag id3v1tag)
          Sets the ID3v1(_1)tag to the tag provided as an argument.
 void setID3v1Tag(Tag id3v1tag)
           
 void setID3v2Tag(AbstractID3v2Tag id3v2tag)
          Sets the v2 tag to the v2 tag provided as an argument.
 void setID3v2Tag(AbstractTag mp3tag)
          Sets the ID3v2 tag for this datatype.
 void setID3v2TagOnly(AbstractID3v2Tag id3v2tag)
          Set v2 tag ,dont need to set v24 tag because saving

TODO temp its rather messy

 void setTag(Tag tag)
          Set the Tag

If the parameter tag is a v1tag then the v1 tag is set if v2tag then the v2tag.

 
Methods inherited from class org.jaudiotagger.audio.AudioFile
checkFilePermissions, getAudioHeader, getBaseFilename, getFile, getTag, getTagOrCreateAndSetDefault, getTagOrCreateDefault, setFile, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_FILESIZE

private static final int MINIMUM_FILESIZE
See Also:
Constant Field Values

tagFormatter

protected static AbstractTagDisplayFormatter tagFormatter

id3v2tag

private AbstractID3v2Tag id3v2tag
the ID3v2 tag that this file contains.


id3v2Asv24tag

private ID3v24Tag id3v2Asv24tag
Representation of the idv2 tag as a idv24 tag


lyrics3tag

private AbstractLyrics3 lyrics3tag
The Lyrics3 tag that this file contains.


id3v1tag

private ID3v1Tag id3v1tag
The ID3v1 tag that this file contains.


LOAD_IDV1TAG

public static final int LOAD_IDV1TAG
See Also:
Constant Field Values

LOAD_IDV2TAG

public static final int LOAD_IDV2TAG
See Also:
Constant Field Values

LOAD_LYRICS3

public static final int LOAD_LYRICS3
This option is currently ignored

See Also:
Constant Field Values

LOAD_ALL

public static final int LOAD_ALL
See Also:
Constant Field Values
Constructor Detail

MP3File

public MP3File()
Creates a new empty MP3File datatype that is not associated with a specific file.


MP3File

public MP3File(java.lang.String filename)
        throws java.io.IOException,
               TagException,
               ReadOnlyFileException,
               InvalidAudioFrameException
Creates a new MP3File datatype and parse the tag from the given filename.

Parameters:
filename - MP3 file
Throws:
java.io.IOException - on any I/O error
TagException - on any exception generated by this library.
ReadOnlyFileException
InvalidAudioFrameException

MP3File

public MP3File(java.io.File file,
               int loadOptions)
        throws java.io.IOException,
               TagException,
               ReadOnlyFileException,
               InvalidAudioFrameException
Creates a new MP3File datatype and parse the tag from the given file Object, files must be writable to use this constructor.

Parameters:
file - MP3 file
loadOptions - decide what tags to load
Throws:
java.io.IOException - on any I/O error
TagException - on any exception generated by this library.
ReadOnlyFileException
InvalidAudioFrameException

MP3File

public MP3File(java.io.File file,
               int loadOptions,
               boolean readOnly)
        throws java.io.IOException,
               TagException,
               ReadOnlyFileException,
               InvalidAudioFrameException
Creates a new MP3File datatype and parse the tag from the given file Object, files can be onpened read only if required.

Parameters:
file - MP3 file
loadOptions - decide what tags to load
readOnly - causes the files to be opened readonly
Throws:
java.io.IOException - on any I/O error
TagException - on any exception generated by this library.
ReadOnlyFileException
InvalidAudioFrameException

MP3File

public MP3File(java.io.File file)
        throws java.io.IOException,
               TagException,
               ReadOnlyFileException,
               InvalidAudioFrameException
Creates a new MP3File datatype and parse the tag from the given file Object.

Parameters:
file - MP3 file
Throws:
java.io.IOException - on any I/O error
TagException - on any exception generated by this library.
ReadOnlyFileException
InvalidAudioFrameException
Method Detail

readV1Tag

private void readV1Tag(java.io.File file,
                       java.io.RandomAccessFile newFile,
                       int loadOptions)
                throws java.io.IOException
Read v1 tag

Parameters:
file -
newFile -
loadOptions -
Throws:
java.io.IOException

readV2Tag

private void readV2Tag(java.io.File file,
                       int loadOptions)
                throws java.io.IOException,
                       TagException
Read V2tag if exists

TODO:shouldnt we be handing TagExceptions:when will they be thrown

Parameters:
file -
loadOptions -
Throws:
java.io.IOException
TagException

readLyrics3Tag

private void readLyrics3Tag(java.io.File file,
                            java.io.RandomAccessFile newFile,
                            int loadOptions)
                     throws java.io.IOException
Read lyrics3 Tag

TODO:not working

Parameters:
file -
newFile -
loadOptions -
Throws:
java.io.IOException

checkAudioStart

private MP3AudioHeader checkAudioStart(long startByte,
                                       MP3AudioHeader currentHeader)
                                throws java.io.IOException,
                                       InvalidAudioFrameException
Regets the audio header starting from start of file, and write appropriate logging to indicate potential problem to user.

Parameters:
startByte -
currentHeader -
Returns:
Throws:
java.io.IOException
InvalidAudioFrameException

getMP3StartByte

public long getMP3StartByte(java.io.File file)
                     throws InvalidAudioFrameException,
                            java.io.IOException
Used by tags when writing to calculate the location of the music file

Parameters:
file -
Returns:
the location within the file that the audio starts
Throws:
java.io.IOException
InvalidAudioFrameException

extractID3v2TagDataIntoFile

public java.io.File extractID3v2TagDataIntoFile(java.io.File outputFile)
                                         throws TagNotFoundException,
                                                java.io.IOException
Extracts the raw ID3v2 tag data into a file.

This provides access to the raw data before manipulation, the data is written from the start of the file to the start of the Audio Data. This is primarily useful for manipulating corrupted tags that are not (fully) loaded using the standard methods.

Parameters:
outputFile - to write the data to
Returns:
Throws:
TagNotFoundException
java.io.IOException

getMP3AudioHeader

public MP3AudioHeader getMP3AudioHeader()
Return audio header

Returns:

hasID3v1Tag

public boolean hasID3v1Tag()
Returns true if this datatype contains an Id3v1 tag

Returns:
true if this datatype contains an Id3v1 tag

hasID3v2Tag

public boolean hasID3v2Tag()
Returns true if this datatype contains an Id3v2 tag

Returns:
true if this datatype contains an Id3v2 tag

setID3v1Tag

public void setID3v1Tag(ID3v1Tag id3v1tag)
Sets the ID3v1(_1)tag to the tag provided as an argument.

Parameters:
id3v1tag -

setID3v1Tag

public void setID3v1Tag(Tag id3v1tag)

setID3v1Tag

public void setID3v1Tag(AbstractTag mp3tag)
Sets the ID3v1 tag for this datatype. A new ID3v1_1 datatype is created from the argument and then used here.

Parameters:
mp3tag - Any MP3Tag datatype can be used and will be converted into a new ID3v1_1 datatype.

getID3v1Tag

public ID3v1Tag getID3v1Tag()
Returns the ID3v1 tag for this datatype.

Returns:
the ID3v1 tag for this datatype

setID3v2Tag

public void setID3v2Tag(AbstractTag mp3tag)
Sets the ID3v2 tag for this datatype. A new ID3v2_4 datatype is created from the argument and then used here.

Parameters:
mp3tag - Any MP3Tag datatype can be used and will be converted into a new ID3v2_4 datatype.

setID3v2Tag

public void setID3v2Tag(AbstractID3v2Tag id3v2tag)
Sets the v2 tag to the v2 tag provided as an argument. Also store a v24 version of tag as v24 is the interface to be used when talking with client applications.

Parameters:
id3v2tag -

setID3v2TagOnly

public void setID3v2TagOnly(AbstractID3v2Tag id3v2tag)
Set v2 tag ,dont need to set v24 tag because saving

TODO temp its rather messy

Parameters:
id3v2tag -

getID3v2Tag

public AbstractID3v2Tag getID3v2Tag()
Returns the ID3v2 tag for this datatype.

Returns:
the ID3v2 tag for this datatype

getID3v2TagAsv24

public ID3v24Tag getID3v2TagAsv24()
Returns:
a representation of tag as v24

delete

public void delete(AbstractTag mp3tag)
            throws java.io.FileNotFoundException,
                   java.io.IOException
Remove tag from file

Parameters:
mp3tag -
Throws:
java.io.FileNotFoundException
java.io.IOException

save

public void save()
          throws java.io.IOException,
                 TagException
Saves the tags in this datatype to the file referred to by this datatype.

Throws:
java.io.IOException - on any I/O error
TagException - on any exception generated by this library.

commit

public void commit()
            throws CannotWriteException
Overriden for comptability with merged code

Overrides:
commit in class AudioFile
Throws:
CannotWriteException
See Also:
AudioFileIO

precheck

public void precheck(java.io.File file)
              throws java.io.IOException
Check can write to file

Parameters:
file -
Throws:
java.io.IOException

save

public void save(java.io.File file)
          throws java.io.IOException
Saves the tags in this datatype to the file argument. It will be saved as TagConstants.MP3_FILE_SAVE_WRITE

Parameters:
file - file to save the this datatype's tags to
Throws:
java.io.FileNotFoundException - if unable to find file
java.io.IOException - on any I/O error

displayStructureAsXML

public java.lang.String displayStructureAsXML()
Displays MP3File Structure

Overrides:
displayStructureAsXML in class AudioFile
Returns:

displayStructureAsPlainText

public java.lang.String displayStructureAsPlainText()
Displays MP3File Structure

Overrides:
displayStructureAsPlainText in class AudioFile
Returns:

createXMLStructureFormatter

private static void createXMLStructureFormatter()

createPlainTextStructureFormatter

private static void createPlainTextStructureFormatter()

getStructureFormatter

public static AbstractTagDisplayFormatter getStructureFormatter()

setTag

public void setTag(Tag tag)
Set the Tag

If the parameter tag is a v1tag then the v1 tag is set if v2tag then the v2tag.

Overrides:
setTag in class AudioFile
Parameters:
tag -

createDefaultTag

public Tag createDefaultTag()
Create Default Tag

Overrides:
createDefaultTag in class AudioFile
Returns: