[Android] AudioUtil: add getCocheFromMemCache
Thomas Guillem
git at videolan.org
Tue Oct 6 18:32:34 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Oct 6 17:52:48 2015 +0200| [7ba60719194b2e069a239f35709e2697bf757ffb] | committer: Thomas Guillem
AudioUtil: add getCocheFromMemCache
This function can be called from Ui thread
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7ba60719194b2e069a239f35709e2697bf757ffb
---
.../src/org/videolan/vlc/gui/audio/AudioUtil.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
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 cbd087d..fb8641d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -274,6 +274,19 @@ public class AudioUtil {
return null;
}
+ private static String getCoverCachePath(Context context, MediaWrapper media, int width) {
+ final int hash = MurmurHash.hash32(Util.getMediaArtist(context, media) + Util.getMediaAlbum(context, media));
+ return COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
+ }
+
+ public static Bitmap getCoverFromMemCache(Context context, MediaWrapper media, int width) {
+ if (media != null && media.getArtist() != null && media.getAlbum() != null) {
+ final BitmapCache cache = BitmapCache.getInstance();
+ return cache.getBitmapFromMemCache(getCoverCachePath(context, media, width));
+ } else
+ return null;
+ }
+
@SuppressLint("NewApi")
public synchronized static Bitmap getCover(Context context, MediaWrapper media, int width) {
BitmapCache cache = BitmapCache.getInstance();
@@ -294,8 +307,7 @@ public class AudioUtil {
try {
// try to load from cache
if (media.getArtist() != null && media.getAlbum() != null) {
- int hash = MurmurHash.hash32(Util.getMediaArtist(context, media) + Util.getMediaAlbum(context, media));
- cachePath = COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
+ cachePath = getCoverCachePath(context, media, width);
// try to get the cover from the LRUCache first
cover = cache.getBitmapFromMemCache(cachePath);
@@ -304,7 +316,7 @@ public class AudioUtil {
// try to get the cover from the storage cache
cacheFile = new File(cachePath);
- if (cacheFile != null && cacheFile.exists()) {
+ if (cacheFile.exists()) {
if (cacheFile.length() > 0)
coverPath = cachePath;
else
More information about the Android
mailing list