本文整理汇总了Java中org.jaudiotagger.tag.TagException类的典型用法代码示例。如果您正苦于以下问题:Java TagException类的具体用法?Java TagException怎么用?Java TagException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TagException类属于org.jaudiotagger.tag包,在下文中一共展示了TagException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
public static Song from(final URI uri) {
try {
AudioFile f = AudioFileIO.read(new File(uri));
Tag tag = f.getTag();
String trackStr = tag.getFirst(FieldKey.TRACK);
if (trackStr.isEmpty()) { return null; }
Artist artist = new Artist(tag.getFirst(FieldKey.ARTIST));
Artwork artwork = tag.getFirstArtwork();
Album album = new Album(tag.getFirst(FieldKey.ALBUM), artwork);
String title = tag.getFirst(FieldKey.TITLE);
int track = Integer.parseInt(trackStr);
Integer seconds = f.getAudioHeader().getTrackLength() + 1;
return new Song(title, artist, album, track, seconds, uri);
} catch (CannotReadException | IOException | TagException | InvalidAudioFrameException
| ReadOnlyFileException e) {
e.printStackTrace();
return null;
}
}
示例2: read
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
* @param byteBuffer
* @throws TagNotFoundException
* @throws IOException
*/
public void read(ByteBuffer byteBuffer) throws TagException
{
byte[] buffer = new byte[5100 + 9 + 11];
String lyricBuffer;
if (!seek(byteBuffer))
{
throw new TagNotFoundException("ID3v1 tag not found");
}
byteBuffer.get(buffer);
lyricBuffer = new String(buffer);
lyric = lyricBuffer.substring(0, lyricBuffer.indexOf("LYRICSEND"));
}
示例3: read
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
public AudioFile read(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
if(logger.isLoggable(Level.CONFIG))
{
logger.config(ErrorMessage.GENERAL_READ.getMsg(path));
}
if (!f.canRead())
{
throw new NoReadPermissionsException(ErrorMessage.GENERAL_READ_FAILED_DO_NOT_HAVE_PERMISSION_TO_READ_FILE.getMsg(f.getAbsolutePath()));
}
if (f.length() <= MINIMUM_SIZE_FOR_VALID_AUDIO_FILE)
{
throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_FILE_TOO_SMALL.getMsg(f.getAbsolutePath()));
}
GenericAudioHeader info = getEncodingInfo(f);
Tag tag = getTag(f);
return new AudioFile(f, info, tag);
}
示例4: readFile
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
*
* Read the tag contained in the given file.
*
*
* @param f The file to read.
* @return The AudioFile with the file tag and the file encoding info.
* @throws org.jaudiotagger.audio.exceptions.CannotReadException If the file could not be read, the extension wasn't
* recognized, or an IO error occurred during the read.
* @throws org.jaudiotagger.tag.TagException
* @throws org.jaudiotagger.audio.exceptions.ReadOnlyFileException
* @throws java.io.IOException
* @throws org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
*/
public AudioFile readFile(File f)
throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
checkFileExists(f);
String ext = Utils.getExtension(f);
AudioFileReader afr = readers.get(ext);
if (afr == null)
{
throw new CannotReadException(ErrorMessage.NO_READER_FOR_THIS_FORMAT.getMsg(ext));
}
AudioFile tempFile = afr.read(f);
tempFile.setExt(ext);
return tempFile;
}
示例5: readFileMagic
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
*
* Read the tag contained in the given file.
*
*
* @param f The file to read.
* @return The AudioFile with the file tag and the file encoding info.
* @throws org.jaudiotagger.audio.exceptions.CannotReadException If the file could not be read, the extension wasn't
* recognized, or an IO error occurred during the read.
* @throws org.jaudiotagger.tag.TagException
* @throws org.jaudiotagger.audio.exceptions.ReadOnlyFileException
* @throws java.io.IOException
* @throws org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
*/
public AudioFile readFileMagic(File f)
throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
checkFileExists(f);
String ext = Utils.getMagicExtension(f);
AudioFileReader afr = readers.get(ext);
if (afr == null)
{
throw new CannotReadException(ErrorMessage.NO_READER_FOR_THIS_FORMAT.getMsg(ext));
}
AudioFile tempFile = afr.read(f);
tempFile.setExt(ext);
return tempFile;
}
示例6: readFileAs
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
*
* Read the tag contained in the given file.
*
*
* @param f The file to read.
* @param ext The extension to be used.
* @return The AudioFile with the file tag and the file encoding info.
* @throws org.jaudiotagger.audio.exceptions.CannotReadException If the file could not be read, the extension wasn't
* recognized, or an IO error occurred during the read.
* @throws org.jaudiotagger.tag.TagException
* @throws org.jaudiotagger.audio.exceptions.ReadOnlyFileException
* @throws java.io.IOException
* @throws org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
*/
public AudioFile readFileAs(File f,String ext)
throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
checkFileExists(f);
// String ext = Utils.getExtension(f);
AudioFileReader afr = readers.get(ext);
if (afr == null)
{
throw new CannotReadException(ErrorMessage.NO_READER_FOR_THIS_FORMAT.getMsg(ext));
}
AudioFile tempFile = afr.read(f);
tempFile.setExt(ext);
return tempFile;
}
示例7: insertLyrics
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
* Insert Lyrics
*
* @param path
* @param lyrics
* @return
*/
public static boolean insertLyrics(String path, String lyrics) {
File f = new File(path);
if (f.exists()) {
try {
AudioFile audioFile = AudioFileIO.read(f);
if (audioFile == null) {
return false;
}
TagOptionSingleton.getInstance().setAndroid(true);
Tag tag = audioFile.getTag();
if (tag == null) {
return false;
}
tag.deleteField(FieldKey.LYRICS);
tag.setField(FieldKey.LYRICS, lyrics);
audioFile.setTag(tag);
AudioFileIO.write(audioFile);
return true;
} catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException | IOException | ReadOnlyFileException e) {
e.printStackTrace();
}
}
return false;
}
示例8: AiffFile
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
public AiffFile(File file, boolean readOnly)
throws IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException {
RandomAccessFile newFile = null;
try {
logger.setLevel(Level.FINEST);
logger.fine("Called AiffFile constructor on " + file.getAbsolutePath());
this.file = file;
//Check File accessibility
newFile = checkFilePermissions(file, readOnly);
audioHeader = new AiffAudioHeader();
//readTag();
} finally {
if (newFile != null) {
newFile.close();
}
}
}
示例9: readTag
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
private Tag readTag(RandomAccessFile file, long tagOffset) throws CannotReadException, IOException {
//Move to start of ID3Tag and read rest of file into ByteBuffer
file.seek(tagOffset);
ByteBuffer tagBuffer = Utils.readFileDataIntoBufferLE(file, (int) (file.length() - file.getFilePointer()));
//Work out ID3 major version
int majorVersion = tagBuffer.get(AbstractID3v2Tag.FIELD_TAG_MAJOR_VERSION_POS);
try {
logger.log(Level.FINE, "Start creating ID3v2 Tag for version: " + majorVersion);
switch (majorVersion) {
case ID3v22Tag.MAJOR_VERSION:
return new ID3v22Tag(tagBuffer, "");
case ID3v23Tag.MAJOR_VERSION:
return new ID3v23Tag(tagBuffer, "");
case ID3v24Tag.MAJOR_VERSION:
return new ID3v24Tag(tagBuffer, "");
default:
logger.log(Level.WARNING, "Unknown major ID3v2 version " + majorVersion + ". Returning an empty ID3v2 Tag.");
return new ID3v24Tag();
}
} catch (TagException e) {
throw new CannotReadException("Could not create ID3v2 Tag");
}
}
示例10: runCommit
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
@Override
protected void runCommit(TableEntry entry)
{
try
{
Tag tag = Utils.getTagFromAudioFile(entry.FilePath);
tag.setField(FieldKey.TITLE, entry.NewTitle);
Utils.saveTagToFile(entry.FilePath, tag);
LOG.log(Level.FINE, "Successfully removed artist name from: " + tag.toString());
}
catch (TagException e)
{
LOG.log(Level.WARNING, "Failed to remove artist name from title: " + entry.FilePath);
}
}
示例11: runCommit
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
@Override
protected void runCommit(TableEntry entry)
{
try
{
Tag tag = AudioFileIO.read(new File(entry.FilePath)).getTag();
tag.setField(FieldKey.TITLE, entry.NewTitle);
tag.setField(FieldKey.TRACK, entry.TrackNumber);
Utils.saveTagToFile(entry.FilePath, tag);
LOG.log(Level.FINE, "Track number removed from name: " + tag.toString());
}
catch (CannotReadException | IOException | TagException
| ReadOnlyFileException| InvalidAudioFrameException e)
{
LOG.log(Level.WARNING, "Failed to write title w/o track num to tag: " + entry.FilePath);
}
}
示例12: getAudioTrackLength
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
public int getAudioTrackLength(URL url) {
try {
// 只能获得本地歌曲文件的信息
AudioFile file = AudioFileIO.read(new File(url.toURI()));
// 获取音频文件的头信息
AudioHeader audioHeader = file.getAudioHeader();
// 文件长度 转换成时间
return audioHeader.getTrackLength();
} catch (CannotReadException | IOException | TagException
| ReadOnlyFileException | InvalidAudioFrameException
| URISyntaxException e) {
e.printStackTrace();
return -1;
}
}
示例13: AiffFile
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
public AiffFile(File file, boolean readOnly)
throws IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException{
RandomAccessFile newFile = null;
try
{
logger.setLevel(Level.FINEST);
logger.fine("Called AiffFile constructor on " + file.getAbsolutePath());
this.file = file;
//Check File accessibility
newFile = checkFilePermissions(file, readOnly);
audioHeader = new AiffAudioHeader();
//readTag();
}
finally
{
if (newFile != null)
{
newFile.close();
}
}
}
示例14: commit
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
/**
* Overridden for compatibility with merged code
*
* @throws CannotWriteException
*/
public void commit() throws CannotWriteException
{
try
{
save();
}
catch (IOException ioe)
{
throw new CannotWriteException(ioe);
}
catch (TagException te)
{
throw new CannotWriteException(te);
}
}
示例15: doInBackground
import org.jaudiotagger.tag.TagException; //导入依赖的package包/类
@Override
protected Boolean doInBackground(Object... params) {
Lyrics editedLyrics = (Lyrics) params[0];
File musicFile = (File) params[1];
boolean failed = false;
if (musicFile != null)
try {
AudioFile af = AudioFileIO.read(musicFile);
TagOptionSingleton.getInstance().setAndroid(true);
Tag tags = af.getTag();
tags.setField(FieldKey.ARTIST, editedLyrics.getArtist());
tags.setField(FieldKey.TITLE, editedLyrics.getTitle());
tags.setField(FieldKey.LYRICS, Html.fromHtml(editedLyrics.getText()).toString());
af.setTag(tags);
AudioFileIO.write(af);
} catch (CannotReadException | IOException | ReadOnlyFileException | TagException
| InvalidAudioFrameException | NullPointerException | CannotWriteException e) {
e.printStackTrace();
failed = true;
}
return failed;
}