use of org.jaudiotagger.tag.TagException in project Shuttle by timusus.
the class LyricsFragment method getLyrics.
public String getLyrics() {
String lyrics = getActivity().getString(R.string.no_lyrics);
String filePath = MusicUtils.getFilePath();
if (filePath == null) {
return lyrics;
}
if (filePath.startsWith("content://")) {
String path = MusicUtils.getFilePath();
if (path != null) {
Query query = new Query.Builder().uri(Uri.parse(path)).projection(new String[] { MediaStore.Audio.Media.DATA }).build();
Cursor cursor = SqlUtils.createQuery(getContext(), query);
if (cursor != null) {
int colIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
if (cursor.moveToFirst()) {
filePath = cursor.getString(colIndex);
}
cursor.close();
}
}
}
File file = new File(filePath);
if (file.exists()) {
try {
AudioFile audioFile = AudioFileIO.read(file);
if (audioFile != null) {
Tag tag = audioFile.getTag();
if (tag != null) {
String tagLyrics = tag.getFirst(FieldKey.LYRICS);
if (tagLyrics != null && tagLyrics.length() != 0) {
lyrics = tagLyrics.replace("\r", "\n");
}
}
}
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | UnsupportedOperationException ignored) {
}
}
return lyrics;
}
use of org.jaudiotagger.tag.TagException in project MusicDNA by harjot-oberai.
the class EditLocalSongFragment method onResume.
@Override
public void onResume() {
super.onResume();
mp3File = null;
try {
File f = new File(HomeActivity.editSong.getPath());
mp3File = (MP3File) AudioFileIO.read(f);
} catch (IOException | CannotReadException | InvalidAudioFrameException | TagException | ReadOnlyFileException e) {
e.printStackTrace();
} catch (ClassCastException e) {
mp3File = null;
e.printStackTrace();
}
if (mp3File == null) {
Toast.makeText(ctx, "Error in loading the file", Toast.LENGTH_SHORT).show();
mCallback.onEditSongSave(false);
}
if (mp3File != null && !mp3File.hasID3v2Tag()) {
Toast.makeText(ctx, "No Tags Found", Toast.LENGTH_SHORT).show();
mCallback.onEditSongSave(false);
}
if (mp3File != null && mp3File.hasID3v2Tag()) {
titleText.setText(HomeActivity.editSong.getTitle());
artistText.setText(HomeActivity.editSong.getArtist());
albumText.setText(HomeActivity.editSong.getAlbum());
}
try {
tag = mp3File.getTag();
id3v1Tag = mp3File.getID3v1Tag();
id3v2Tag = mp3File.getID3v2Tag();
id3v24Tag = mp3File.getID3v2TagAsv24();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ctx, "Error in finding tags", Toast.LENGTH_SHORT).show();
mCallback.onEditSongSave(false);
}
}
use of org.jaudiotagger.tag.TagException in project musiccabinet by hakko.
the class AudioTagService method updateMetadata.
public void updateMetadata(File file) {
String extension = getExtension(file.getFilename()).toUpperCase();
if (!ALLOWED_EXTENSIONS.contains(extension)) {
return;
}
MetaData metaData = new MetaData();
metaData.setMediaType(Mediatype.valueOf(extension));
try {
AudioFile audioFile = AudioFileIO.read(new java.io.File(file.getDirectory(), file.getFilename()));
Tag tag = audioFile.getTag();
if (tag != null) {
metaData.setArtist(getTagField(tag, ARTIST));
metaData.setArtistSort(getTagField(tag, ARTIST_SORT));
metaData.setAlbumArtist(toAlbumArtist(tag));
metaData.setAlbumArtistSort(getTagField(tag, ALBUM_ARTIST_SORT));
metaData.setAlbum(toAlbum(getTagField(tag, ALBUM)));
metaData.setTitle(getTagField(tag, TITLE));
metaData.setYear(getTagField(tag, YEAR));
metaData.setGenre(toGenre(getTagField(tag, GENRE)));
metaData.setLyrics(getTagField(tag, LYRICS));
metaData.setComposer(getTagField(tag, COMPOSER));
metaData.setDiscNr(toFirstNumber(getTagField(tag, DISC_NO)));
metaData.setDiscNrs(toShort(getTagField(tag, DISC_TOTAL)));
metaData.setTrackNr(toFirstNumber(getTagField(tag, TRACK)));
metaData.setTrackNrs(toShort(getTagField(tag, TRACK_TOTAL)));
metaData.setCoverArtEmbedded(tag.getFirstArtwork() != null);
}
AudioHeader audioHeader = audioFile.getAudioHeader();
if (audioHeader != null) {
metaData.setVbr(audioHeader.isVariableBitRate());
metaData.setBitrate((short) audioHeader.getBitRateAsNumber());
metaData.setDuration((short) audioHeader.getTrackLength());
}
file.setMetaData(metaData);
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | RuntimeException e) {
// AudioFileIO has been seen to throw NumberFormatException
LOG.warn("Could not read metadata of file " + file.getFilename() + " from " + file.getDirectory(), e);
}
}
use of org.jaudiotagger.tag.TagException in project musiccabinet by hakko.
the class AudioTagService method getArtwork.
public Artwork getArtwork(java.io.File file) throws ApplicationException {
Tag tag = null;
try {
AudioFile audioFile = AudioFileIO.read(file);
tag = audioFile.getTag();
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | RuntimeException e) {
throw new ApplicationException("Failed reading artwork from file " + file, e);
}
return tag == null ? null : tag.getFirstArtwork();
}
use of org.jaudiotagger.tag.TagException in project MusicDNA by harjot-oberai.
the class AsfFileReader method read.
/**
* {@inheritDoc}
*/
@Override
public AudioFile read(final File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException {
if (!f.canRead()) {
throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_DO_NOT_HAVE_PERMISSION_TO_READ_FILE.getMsg(f.getAbsolutePath()));
}
InputStream stream = null;
try {
stream = new FullRequestInputStream(new BufferedInputStream(new FileInputStream(f)));
final AsfHeader header = HEADER_READER.read(Utils.readGUID(stream), stream, 0);
if (header == null) {
throw new CannotReadException(ErrorMessage.ASF_HEADER_MISSING.getMsg(f.getAbsolutePath()));
}
if (header.getFileHeader() == null) {
throw new CannotReadException(ErrorMessage.ASF_FILE_HEADER_MISSING.getMsg(f.getAbsolutePath()));
}
// Just log a warning because file seems to play okay
if (header.getFileHeader().getFileSize().longValue() != f.length()) {
logger.warning(ErrorMessage.ASF_FILE_HEADER_SIZE_DOES_NOT_MATCH_FILE_SIZE.getMsg(f.getAbsolutePath(), header.getFileHeader().getFileSize().longValue(), f.length()));
}
return new AudioFile(f, getAudioHeader(header), getTag(header));
} catch (final CannotReadException e) {
throw e;
} catch (final Exception e) {
throw new CannotReadException("\"" + f + "\" :" + e, e);
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (final Exception ex) {
LOGGER.severe("\"" + f + "\" :" + ex);
}
}
}
Aggregations