Fixed scrolling lags when loading album covers directly from their song files.
This commit is contained in:
parent
1350454484
commit
e1f0b32e9f
4 changed files with 46 additions and 33 deletions
|
|
@ -15,6 +15,7 @@ import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
|||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
import org.jaudiotagger.tag.images.Artwork;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
|
@ -73,14 +74,9 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
|||
if (PreferenceUtil.getInstance(context).ignoreMediaStoreArtwork()) {
|
||||
ArrayList<Song> songs = AlbumSongLoader.getAlbumSongList(context, albumId);
|
||||
for (Song song : songs) {
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(new File(song.data));
|
||||
byte[] albumCover = audioFile.getTagOrCreateAndSetDefault().getFirstArtwork().getBinaryData();
|
||||
if (albumCover != null) {
|
||||
return new ByteArrayInputStream(albumCover);
|
||||
}
|
||||
} catch (@NonNull Exception e) {
|
||||
e.printStackTrace();
|
||||
byte[] albumCover = getAlbumCoverBinaryData(new File(song.data));
|
||||
if (albumCover != null) {
|
||||
return new ByteArrayInputStream(albumCover);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -92,14 +88,9 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
|||
String[] data = imageUri.substring(SCHEME_SONG.length()).split("#", 2);
|
||||
|
||||
if (PreferenceUtil.getInstance(context).ignoreMediaStoreArtwork()) {
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(new File(data[1]));
|
||||
byte[] albumCover = audioFile.getTagOrCreateAndSetDefault().getFirstArtwork().getBinaryData();
|
||||
if (albumCover != null) {
|
||||
return new ByteArrayInputStream(albumCover);
|
||||
}
|
||||
} catch (@NonNull Exception e) {
|
||||
e.printStackTrace();
|
||||
byte[] albumCover = getAlbumCoverBinaryData(new File(data[1]));
|
||||
if (albumCover != null) {
|
||||
return new ByteArrayInputStream(albumCover);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +98,20 @@ public class PhonographImageDownloader extends BaseImageDownloader {
|
|||
return getMediaProviderAlbumArtInputStream(id);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static byte[] getAlbumCoverBinaryData(File song) {
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(song);
|
||||
Artwork artwork = audioFile.getTagOrCreateAndSetDefault().getFirstArtwork();
|
||||
if (artwork != null) {
|
||||
return artwork.getBinaryData();
|
||||
}
|
||||
} catch (@NonNull Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private InputStream getMediaProviderAlbumArtInputStream(int albumId) throws
|
||||
FileNotFoundException {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue