[Android] Add bitmap caching to AudioUtil
Ludovic Fauvet
git at videolan.org
Mon Oct 15 19:16:55 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Oct 15 19:12:59 2012 +0200| [3e319ecd1f2b6e76f11ea3d757df52f8b16ef6f3] | committer: Ludovic Fauvet
Add bitmap caching to AudioUtil
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3e319ecd1f2b6e76f11ea3d757df52f8b16ef6f3
---
vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index 2d238da..183104f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -29,6 +29,7 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import org.videolan.vlc.BitmapCache;
import org.videolan.vlc.Media;
import org.videolan.vlc.MurmurHash;
import org.videolan.vlc.R;
@@ -172,6 +173,14 @@ public class AudioUtil {
// try to load from cache
int hash = MurmurHash.hash32(media.getArtist()+media.getAlbum());
cachePath = COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
+
+ BitmapCache cache = BitmapCache.getInstance();
+ // try to get the cover from the LRUCache first
+ cover = cache.getBitmapFromMemCache(cachePath);
+ if (cover != null)
+ return cover;
+
+ // try to get the cover from the storage cache
File cacheFile = new File(cachePath);
if (cacheFile != null && cacheFile.exists()) {
if (cacheFile.length() > 0)
@@ -194,8 +203,9 @@ public class AudioUtil {
// read (and scale?) the bitmap
cover = readCoverBitmap(context, coverPath, width);
- // store cover into cache
+ // store cover into both cache
writeBitmap(cover, cachePath);
+ cache.addBitmapToMemCache(cachePath, cover);
} catch (Exception e) {
e.printStackTrace();
More information about the Android
mailing list