Search in sources :

Example 21 with TagException

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)));
}
Also used : ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull) Song(com.simplecity.amp_library.model.Song) AudioFile(org.jaudiotagger.audio.AudioFile) MediaStore(android.provider.MediaStore) Observable(io.reactivex.Observable) Cursor(android.database.Cursor) FieldKey(org.jaudiotagger.tag.FieldKey) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackpressureStrategy(io.reactivex.BackpressureStrategy) IntentFilter(android.content.IntentFilter) TextUtils(android.text.TextUtils) IOException(java.io.IOException) Tag(org.jaudiotagger.tag.Tag) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) File(java.io.File) Query(com.simplecity.amp_library.model.Query) Presenter(com.simplecity.amp_library.ui.presenters.Presenter) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) TagException(org.jaudiotagger.tag.TagException) AudioFileIO(org.jaudiotagger.audio.AudioFileIO) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) Query(com.simplecity.amp_library.model.Query) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) IOException(java.io.IOException) Cursor(android.database.Cursor) AudioFile(org.jaudiotagger.audio.AudioFile) TagException(org.jaudiotagger.tag.TagException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) Tag(org.jaudiotagger.tag.Tag) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File)

Aggregations

TagException (org.jaudiotagger.tag.TagException)21 CannotReadException (org.jaudiotagger.audio.exceptions.CannotReadException)20 InvalidAudioFrameException (org.jaudiotagger.audio.exceptions.InvalidAudioFrameException)20 ReadOnlyFileException (org.jaudiotagger.audio.exceptions.ReadOnlyFileException)20 IOException (java.io.IOException)19 AudioFile (org.jaudiotagger.audio.AudioFile)16 File (java.io.File)13 Tag (org.jaudiotagger.tag.Tag)13 CannotWriteException (org.jaudiotagger.audio.exceptions.CannotWriteException)8 Cursor (android.database.Cursor)6 Paint (android.graphics.Paint)5 ContentValues (android.content.ContentValues)4 FieldDataInvalidException (org.jaudiotagger.tag.FieldDataInvalidException)4 KeyNotFoundException (org.jaudiotagger.tag.KeyNotFoundException)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 OnClickListener (android.content.DialogInterface.OnClickListener)3 CompoundButton (android.widget.CompoundButton)3 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)3 Query (com.simplecity.amp_library.model.Query)3