From 56a6ff56f038af853fe27308f6462a30d60bf2c1 Mon Sep 17 00:00:00 2001 From: Martin Disch Date: Wed, 20 Jun 2018 15:15:35 +0200 Subject: [PATCH] Use JAudiotagger instead of mp3agic --- app/build.gradle | 1 - .../audiocover/AudioFileCoverFetcher.java | 25 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1ee84c29..665d52d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -137,6 +137,5 @@ dependencies { transitive = true } implementation 'com.google.code.gson:gson:2.8.2' - implementation 'com.mpatric:mp3agic:0.9.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/app/src/main/java/com/kabouzeid/gramophone/glide/audiocover/AudioFileCoverFetcher.java b/app/src/main/java/com/kabouzeid/gramophone/glide/audiocover/AudioFileCoverFetcher.java index 930548a2..efacb32f 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/glide/audiocover/AudioFileCoverFetcher.java +++ b/app/src/main/java/com/kabouzeid/gramophone/glide/audiocover/AudioFileCoverFetcher.java @@ -4,10 +4,12 @@ import android.media.MediaMetadataRetriever; import com.bumptech.glide.Priority; import com.bumptech.glide.load.data.DataFetcher; -import com.mpatric.mp3agic.ID3v2; -import com.mpatric.mp3agic.InvalidDataException; -import com.mpatric.mp3agic.Mp3File; -import com.mpatric.mp3agic.UnsupportedTagException; + +import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; +import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; +import org.jaudiotagger.audio.mp3.MP3File; +import org.jaudiotagger.tag.TagException; +import org.jaudiotagger.tag.images.Artwork; import java.io.ByteArrayInputStream; import java.io.File; @@ -54,18 +56,19 @@ public class AudioFileCoverFetcher implements DataFetcher { private InputStream fallback(String path) throws FileNotFoundException { // Method 1: use embedded high resolution album art if there is any try { - Mp3File mp3File = new Mp3File(path); - if (mp3File.hasId3v2Tag()) { - ID3v2 id3v2Tag = mp3File.getId3v2Tag(); - byte[] imageData = id3v2Tag.getAlbumImage(); - if (imageData != null) { + MP3File mp3File = new MP3File(path); + if (mp3File.hasID3v2Tag()) { + Artwork art = mp3File.getTag().getFirstArtwork(); + if (art != null) { + byte[] imageData = art.getBinaryData(); return new ByteArrayInputStream(imageData); } } // If there are any exceptions, we ignore them and continue to the other fallback method + } catch (ReadOnlyFileException ignored) { + } catch (InvalidAudioFrameException ignored) { + } catch (TagException ignored) { } catch (IOException ignored) { - } catch (InvalidDataException ignored) { - } catch (UnsupportedTagException ignored) { } // Method 2: look for album art in external files