public class AudioFileIO extends Object
AudioFile audioFile = AudioFileIO.read(new File("audiofile.mp3")); //Reads the given file.
int bitrate = audioFile.getBitrate(); //Retreives the bitrate of the file.
String artist = audioFile.getTag().getFirst(TagFieldKey.ARTIST); //Retreive the artist name.
audioFile.getTag().setGenre("Progressive Rock"); //Sets the genre to Prog. Rock, note the file on disk is still unmodified.
AudioFileIO.write(audioFile); //Write the modifications in the file on disk.
You can also use the commit()
method defined for
AudioFile
s to achieve the same goal as
AudioFileIO.write(File)
, like this:
AudioFile audioFile = AudioFileIO.read(new File("audiofile.mp3"));
audioFile.getTag().setGenre("Progressive Rock");
audioFile.commit(); //Write the modifications in the file on disk.
Constructor and Description |
---|
AudioFileIO()
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addAudioFileModificationListener(AudioFileModificationListener listener)
Adds an listener for all file formats.
|
void |
checkFileExists(File file)
Check does file exist
|
static void |
delete(AudioFile f)
Delete the tag, if any, contained in the given file.
|
void |
deleteTag(AudioFile f)
Delete the tag, if any, contained in the given file.
|
static AudioFileIO |
getDefaultAudioFileIO()
This method returns the default instance for static use.
|
static AudioFile |
read(File f)
Read the tag contained in the given file.
|
static AudioFile |
readAs(File f,
String ext)
Read the tag contained in the given file.
|
AudioFile |
readFile(File f)
Read the tag contained in the given file.
|
AudioFile |
readFileAs(File f,
String ext)
Read the tag contained in the given file.
|
AudioFile |
readFileMagic(File f)
Read the tag contained in the given file.
|
static AudioFile |
readMagic(File f)
Read the tag contained in the given file.
|
void |
removeAudioFileModificationListener(AudioFileModificationListener listener)
Removes a listener for all file formats.
|
static void |
write(AudioFile f)
Write the tag contained in the audioFile in the actual file on the disk.
|
static void |
writeAs(AudioFile f,
String targetPath)
Write the tag contained in the audioFile in the actual file on the disk.
|
void |
writeFile(AudioFile f,
String targetPath)
Write the tag contained in the audioFile in the actual file on the disk.
|
public static Logger logger
public static void delete(AudioFile f) throws CannotReadException, CannotWriteException
f
- The file where the tag will be deletedCannotWriteException
- If the file could not be written/accessed, the extension
wasn't recognized, or other IO error occurred.CannotReadException
public static AudioFileIO getDefaultAudioFileIO()
public static AudioFile readAs(File f, String ext) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.ext
- The extension to be used.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public static AudioFile readMagic(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public static AudioFile read(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public static void write(AudioFile f) throws CannotWriteException
f
- The AudioFile to be writtenNoWritePermissionsException
- 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 occurred.public static void writeAs(AudioFile f, String targetPath) throws CannotWriteException
f
- The AudioFile to be writtentargetPath
- The AudioFile path to which to be written without the extension. Cannot be nullNoWritePermissionsException
- 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 occurred.public void addAudioFileModificationListener(AudioFileModificationListener listener)
listener
- listenerpublic void deleteTag(AudioFile f) throws CannotReadException, CannotWriteException
f
- The file where the tag will be deletedCannotWriteException
- If the file could not be written/accessed, the extension
wasn't recognized, or other IO error occurred.CannotReadException
public AudioFile readFile(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public AudioFile readFileMagic(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public AudioFile readFileAs(File f, String ext) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
f
- The file to read.ext
- The extension to be used.CannotReadException
- If the file could not be read, the extension wasn't
recognized, or an IO error occurred during the read.TagException
ReadOnlyFileException
IOException
InvalidAudioFrameException
public void checkFileExists(File file) throws FileNotFoundException
file
- FileNotFoundException
public void removeAudioFileModificationListener(AudioFileModificationListener listener)
listener
- listenerpublic void writeFile(AudioFile f, String targetPath) throws CannotWriteException
f
- The AudioFile to be writtentargetPath
- a file path, without an extension, which provides a "save as". If null, then normal "save" functionNoWritePermissionsException
- 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 occurred.Copyright © 2005–2020 jthink.net. All rights reserved.