Fix loading of large embedded album art
Android's MediaMetadataRetriever.getEmbeddedPicture() fails on large images, because ID3 metadata that is considered too big is skipped.
This commit is contained in:
parent
436a3c90ee
commit
0400bda7cd
2 changed files with 22 additions and 0 deletions
|
|
@ -137,5 +137,6 @@ dependencies {
|
||||||
transitive = true
|
transitive = true
|
||||||
}
|
}
|
||||||
implementation 'com.google.code.gson:gson:2.8.2'
|
implementation 'com.google.code.gson:gson:2.8.2'
|
||||||
|
implementation 'com.mpatric:mp3agic:0.9.1'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ import android.media.MediaMetadataRetriever;
|
||||||
|
|
||||||
import com.bumptech.glide.Priority;
|
import com.bumptech.glide.Priority;
|
||||||
import com.bumptech.glide.load.data.DataFetcher;
|
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 java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -48,6 +52,23 @@ public class AudioFileCoverFetcher implements DataFetcher<InputStream> {
|
||||||
private static final String[] FALLBACKS = {"cover.jpg", "album.jpg", "folder.jpg", "cover.png", "album.png", "folder.png"};
|
private static final String[] FALLBACKS = {"cover.jpg", "album.jpg", "folder.jpg", "cover.png", "album.png", "folder.png"};
|
||||||
|
|
||||||
private InputStream fallback(String path) throws FileNotFoundException {
|
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) {
|
||||||
|
return new ByteArrayInputStream(imageData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If there are any exceptions, we ignore them and continue to the other fallback method
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
} catch (InvalidDataException ignored) {
|
||||||
|
} catch (UnsupportedTagException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method 2: look for album art in external files
|
||||||
File parent = new File(path).getParentFile();
|
File parent = new File(path).getParentFile();
|
||||||
for (String fallback : FALLBACKS) {
|
for (String fallback : FALLBACKS) {
|
||||||
File cover = new File(parent, fallback);
|
File cover = new File(parent, fallback);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue