use of org.jaudiotagger.tag.TagException in project Shuttle by timusus.
the class LyricsPresenter method updateLyrics.
private void updateLyrics() {
addDisposable(Observable.fromCallable(() -> {
String lyrics = "";
String path = MusicUtils.getFilePath();
if (TextUtils.isEmpty(path)) {
return lyrics;
}
if (path.startsWith("content://")) {
Query query = new Query.Builder().uri(Uri.parse(path)).projection(new String[] { MediaStore.Audio.Media.DATA }).build();
Cursor cursor = SqlUtils.createQuery(ShuttleApplication.getInstance(), query);
if (cursor != null) {
try {
int colIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
if (cursor.moveToFirst()) {
path = cursor.getString(colIndex);
}
} finally {
cursor.close();
}
}
}
File file = new File(path);
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;
}).subscribe(lyrics -> {
LyricsView lyricsView = getView();
if (lyricsView != null) {
lyricsView.updateLyrics(lyrics);
lyricsView.showNoLyricsView(TextUtils.isEmpty(lyrics));
lyricsView.showQuickLyricInfoButton(!QuickLyricUtils.isQLInstalled());
}
}, error -> LogUtils.logException(TAG, "Error getting lyrics", error)));
}
Aggregations