org.jaudiotagger.audio
Class AudioFile

java.lang.Object
  extended by org.jaudiotagger.audio.AudioFile
Direct Known Subclasses:
MP3File

public class AudioFile
extends java.lang.Object

This is the main object manipulated by the user representing an audiofile, its properties and its tag.

The prefered way to obtain an AudioFile is to use the AudioFileIO.read(File) method.

The AudioFile contains every properties associated with the file itself (no meta-data), like the bitrate, the sampling rate, the encoding audioHeaders, etc.

To get the meta-data contained in this file you have to get the Tag of this AudioFile

Since:
v0.01
Version:
$Id: AudioFile.java,v 1.15 2009/11/12 15:43:00 paultaylor Exp $
Author:
Raphael Slinckx
See Also:
AudioFileIO, Tag

Field Summary
protected  AudioHeader audioHeader
          The Audio header info
protected  java.io.File file
          The physical file that this instance represents.
static java.util.logging.Logger logger
           
protected  Tag tag
          The tag
 
Constructor Summary
AudioFile()
           
AudioFile(java.io.File f, AudioHeader audioHeader, Tag tag)
          These constructors are used by the different readers, users should not use them, but use the AudioFileIO.read(File) method instead !.
AudioFile(java.lang.String s, AudioHeader audioHeader, Tag tag)
          These constructors are used by the different readers, users should not use them, but use the AudioFileIO.read(File) method instead !.
 
Method Summary
protected  java.io.RandomAccessFile checkFilePermissions(java.io.File file, boolean readOnly)
          Checks the file is accessible with the correct permissions, otherwise exception occurs
 void commit()
          Write the tag contained in this AudioFile in the actual file on the disk, this is the same as calling the AudioFileIO.write(this) method.
 Tag createDefaultTag()
          Create Default Tag
 java.lang.String displayStructureAsPlainText()
          Optional debugging method
 java.lang.String displayStructureAsXML()
          Optional debugging method
 AudioHeader getAudioHeader()
          Return audio header
static java.lang.String getBaseFilename(java.io.File file)
           
 java.io.File getFile()
          Retrieve the physical file
 Tag getTag()
          Returns the tag contained in this AudioFile, the Tag contains any useful meta-data, like artist, album, title, etc.
 Tag getTagOrCreateAndSetDefault()
          Get the tag or if the file doesnt have one at all, create a default tag and set it
 Tag getTagOrCreateDefault()
          Get the tag or if the file doesnt have one at all, create a default tag and return
 void setFile(java.io.File file)
          Set the file to store the info in
 void setTag(Tag tag)
           
 java.lang.String toString()
          Returns a multi-line string with the file path, the encoding audioHeaderrmations, and the tag contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger

file

protected java.io.File file
The physical file that this instance represents.


audioHeader

protected AudioHeader audioHeader
The Audio header info


tag

protected Tag tag
The tag

Constructor Detail

AudioFile

public AudioFile()

AudioFile

public AudioFile(java.io.File f,
                 AudioHeader audioHeader,
                 Tag tag)

These constructors are used by the different readers, users should not use them, but use the AudioFileIO.read(File) method instead !.

Create the AudioFile representing file f, the encodingaudioHeaders and containing the tag

Parameters:
f - The file of the audiofile
audioHeader - the encoding audioHeaders over this file
tag - the tag contained in this file or null if no tag exists

AudioFile

public AudioFile(java.lang.String s,
                 AudioHeader audioHeader,
                 Tag tag)

These constructors are used by the different readers, users should not use them, but use the AudioFileIO.read(File) method instead !.

Create the AudioFile representing file denoted by pathname s, the encodingaudioHeaders and containing the tag

Parameters:
s - The pathname of the audiofile
audioHeader - the encoding audioHeaders over this file
tag - the tag contained in this file
Method Detail

commit

public void commit()
            throws CannotWriteException

Write the tag contained in this AudioFile in the actual file on the disk, this is the same as calling the AudioFileIO.write(this) method.

Throws:
CannotWriteException - If the file could not be written/accessed, the extension wasn't recognized, or other IO error occured.
See Also:
AudioFileIO

setFile

public void setFile(java.io.File file)
Set the file to store the info in

Parameters:
file -

getFile

public java.io.File getFile()
Retrieve the physical file

Returns:

setTag

public void setTag(Tag tag)

getAudioHeader

public AudioHeader getAudioHeader()
Return audio header

Returns:

getTag

public Tag getTag()

Returns the tag contained in this AudioFile, the Tag contains any useful meta-data, like artist, album, title, etc. If the file does not contain any tag the null is returned. Some audio formats do not allow there to be no tag so in this case the reader would return an empty tag whereas for others such as mp3 it is purely optional.

Returns:
Returns the tag contained in this AudioFile, or null if no tag exists.

toString

public java.lang.String toString()

Returns a multi-line string with the file path, the encoding audioHeaderrmations, and the tag contents.

Overrides:
toString in class java.lang.Object
Returns:
A multi-line string with the file path, the encoding audioHeaderrmations, and the tag contents. TODO Maybe this can be changed ?

checkFilePermissions

protected java.io.RandomAccessFile checkFilePermissions(java.io.File file,
                                                        boolean readOnly)
                                                 throws ReadOnlyFileException,
                                                        java.io.FileNotFoundException
Checks the file is accessible with the correct permissions, otherwise exception occurs

Parameters:
file -
readOnly -
Returns:
Throws:
ReadOnlyFileException
java.io.FileNotFoundException

displayStructureAsXML

public java.lang.String displayStructureAsXML()
Optional debugging method

Returns:

displayStructureAsPlainText

public java.lang.String displayStructureAsPlainText()
Optional debugging method

Returns:

createDefaultTag

public Tag createDefaultTag()
Create Default Tag

Returns:

getTagOrCreateDefault

public Tag getTagOrCreateDefault()
Get the tag or if the file doesnt have one at all, create a default tag and return

Returns:

getTagOrCreateAndSetDefault

public Tag getTagOrCreateAndSetDefault()
Get the tag or if the file doesnt have one at all, create a default tag and set it

Returns:

getBaseFilename

public static java.lang.String getBaseFilename(java.io.File file)
Parameters:
file -
Returns:
filename with audioformat seperator stripped of.