public class AudioFile extends Object
This is the main object manipulated by the user representing an audiofile, its properties and its tag.
The preferred way to obtain an AudioFile
is to use the AudioFileIO.read(File)
method.
The AudioHeader
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
AudioFileIO
,
Tag
Modifier and Type | Field and Description |
---|---|
protected AudioHeader |
audioHeader
The Audio header info
|
protected String |
extension
The tag
|
protected File |
file
The physical file that this instance represents.
|
static Logger |
logger |
protected Tag |
tag
The tag
|
Constructor and Description |
---|
AudioFile() |
AudioFile(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(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 !. |
Modifier and Type | Method and Description |
---|---|
void |
checkFileExists(File file)
Check does file exist
|
protected RandomAccessFile |
checkFilePermissions(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. |
AbstractID3v2Tag |
convertID3Tag(AbstractID3v2Tag tag,
ID3V2Version id3V2Version)
If using ID3 format convert tag from current version to another as specified by id3V2Version,
|
Tag |
createDefaultTag()
Create Default Tag
|
void |
delete()
Delete any tags that exist in the fie , this is the same as calling the
AudioFileIO.delete(this) method. |
String |
displayStructureAsPlainText()
Optional debugging method.
|
String |
displayStructureAsXML()
Optional debugging method.
|
AudioHeader |
getAudioHeader()
Return audio header information
|
static String |
getBaseFilename(File file) |
String |
getExt()
Retrieve the file extension
|
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 |
getTagAndConvertOrCreateAndSetDefault()
Get the tag and convert to the default tag version or if the file doesn't have one at all, create a default tag
set as tag for this file
Conversions are currently only necessary/available for some formats that support ID3- Dsf, Mp3
|
Tag |
getTagAndConvertOrCreateDefault()
Get the tag and convert to the default tag version or if the file doesn't have one at all, create a default tag
Conversions are currently only necessary/available for some formats that support ID3- Dsf, Mp3
|
Tag |
getTagOrCreateAndSetDefault()
Get the tag or if the file doesn't have one at all, create a default tag and set it
as the tag of this file
|
Tag |
getTagOrCreateDefault()
Get the tag or if the file doesn't have one at all, create a default tag and return
|
void |
setExt(String ext)
Set the file extension
|
void |
setFile(File file)
Set the file to store the info in
|
void |
setTag(Tag tag)
Assign a tag to this audio file
|
String |
toString()
Returns a multi-line string with the file path, the encoding audioHeader, and the tag contents.
|
public static Logger logger
protected File file
protected AudioHeader audioHeader
protected Tag tag
protected String extension
public AudioFile()
public AudioFile(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 encoding audio headers and containing the tag
f
- The file of the audio fileaudioHeader
- the encoding audioHeaders over this filetag
- the tag contained in this file or null if no tag existspublic AudioFile(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 pathnames, the encoding audio Headers and containing the tag
s
- The pathname of the audio fileaudioHeader
- the encoding audioHeaders over this filetag
- the tag contained in this filepublic 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.
NoWritePermissionsException
- if the file could not be written to due to file permissionsCannotWriteException
- If the file could not be written/accessed, the extension wasn't recognized, or other IO error occured.AudioFileIO
public void delete() throws CannotReadException, CannotWriteException
Delete any tags that exist in the fie , this is the same as calling the AudioFileIO.delete(this)
method.
CannotWriteException
- If the file could not be written/accessed, the extension wasn't recognized, or other IO error occured.CannotReadException
AudioFileIO
public void setFile(File file)
file
- public File getFile()
public void setExt(String ext)
ext
- public String getExt()
public void setTag(Tag tag)
tag
- Tag to be assignedpublic AudioHeader getAudioHeader()
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.
public String toString()
Returns a multi-line string with the file path, the encoding audioHeader, and the tag contents.
public void checkFileExists(File file) throws FileNotFoundException
file
- FileNotFoundException
- if file not foundprotected RandomAccessFile checkFilePermissions(File file, boolean readOnly) throws ReadOnlyFileException, FileNotFoundException, CannotReadException
file
- readOnly
- ReadOnlyFileException
FileNotFoundException
CannotReadException
public String displayStructureAsXML()
public String displayStructureAsPlainText()
public Tag createDefaultTag()
public Tag getTagOrCreateDefault()
public Tag getTagOrCreateAndSetDefault()
public Tag getTagAndConvertOrCreateDefault()
public Tag getTagAndConvertOrCreateAndSetDefault()
public static String getBaseFilename(File file)
file
- public AbstractID3v2Tag convertID3Tag(AbstractID3v2Tag tag, ID3V2Version id3V2Version)
Copyright © 2005–2020 jthink.net. All rights reserved.