[Android] No cache store for Unknown artist/album media

Geoffrey Métais git at videolan.org
Thu Apr 16 17:31:56 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 16 17:09:06 2015 +0200| [0569213394a39412574c95d155e6964d886716fd] | committer: Geoffrey Métais

No cache store for Unknown artist/album media

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0569213394a39412574c95d155e6964d886716fd
---

 .../src/org/videolan/vlc/gui/audio/AudioUtil.java  |   41 +++++++++++---------
 1 file changed, 23 insertions(+), 18 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 88c45da..a1fcab3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -232,9 +232,11 @@ public class AudioUtil {
 
     @SuppressLint("NewApi")
     public synchronized static Bitmap getCover(Context context, MediaWrapper media, int width) {
+        BitmapCache cache = BitmapCache.getInstance();
         String coverPath = null;
         Bitmap cover = null;
         String cachePath = null;
+        File cacheFile = null;
 
         if (width <= 0) {
             Log.e(TAG, "Invalid cover width requested");
@@ -247,22 +249,23 @@ public class AudioUtil {
 
         try {
             // try to load from cache
-            int hash = MurmurHash.hash32(Util.getMediaArtist(context, media)+Util.getMediaAlbum(context, media));
-            cachePath = COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
-
-            // try to get the cover from the LRUCache first
-            BitmapCache cache = BitmapCache.getInstance();
-            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)
-                    coverPath = cachePath;
-                else
-                    return null;
+            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;
+
+                // 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
+                cacheFile = new File(cachePath);
+                if (cacheFile != null && cacheFile.exists()) {
+                    if (cacheFile.length() > 0)
+                        coverPath = cachePath;
+                    else
+                        return null;
+                }
             }
 
             // try to get it from VLC
@@ -281,8 +284,10 @@ public class AudioUtil {
             cover = readCoverBitmap(coverPath, width);
 
             // store cover into both cache
-            writeBitmap(cover, cachePath);
-            cache.addBitmapToMemCache(cachePath, cover);
+            if (cachePath != null) {
+                writeBitmap(cover, cachePath);
+                cache.addBitmapToMemCache(cachePath, cover);
+            }
 
         } catch (Exception e) {
             e.printStackTrace();



More information about the Android mailing list