[Android] [PATCH] Use the icon cache as additional source for cover art

Marc K morckx at gmail.com
Sun Nov 27 21:05:50 CET 2016


This fixes showing the cover art of network media if it was previously
shown as icon in the browser.

Signed-off-by: Marc K <morckx at gmail.com>
---
 .../src/org/videolan/vlc/gui/helpers/AudioUtil.java     | 17 +++++++++++------
 .../src/org/videolan/vlc/util/HttpImageLoader.java      | 11 +++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
index 846f996..82ad0dd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
@@ -32,6 +32,7 @@ import android.graphics.drawable.BitmapDrawable;
 import android.media.RingtoneManager;
 import android.net.Uri;
 import android.provider.MediaStore;
+import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -42,6 +43,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.HttpImageLoader;
 import org.videolan.vlc.util.MurmurHash;
 import org.videolan.vlc.util.Permissions;
 import org.videolan.vlc.util.Util;
@@ -283,11 +285,16 @@ public class AudioUtil {
     }
 
     public static Bitmap getCoverFromMemCache(Context context, MediaWrapper media, int width) {
+        Bitmap cover = null;
+
         if (media != null && media.getArtist() != null && media.getAlbum() != null) {
             final BitmapCache cache = BitmapCache.getInstance();
-            return cache.getBitmapFromMemCache(getCoverCachePath(context, media, width));
-        } else
-            return null;
+            cover = cache.getBitmapFromMemCache(getCoverCachePath(context, media, width));
+        }
+        if (cover == null && media != null && !TextUtils.isEmpty(media.getArtworkURL()) && media.getArtworkURL().startsWith("http")) {
+            cover = HttpImageLoader.getBitmapFromIconCache(media.getArtworkURL());
+        }
+        return cover;
     }
 
     @SuppressLint("NewApi")
@@ -322,10 +329,8 @@ public class AudioUtil {
                 if (cacheFile.exists()) {
                     if (cacheFile.length() > 0)
                         coverPath = cachePath;
-                    else
-                        return null;
                 }
-            }
+            } else
 
             // try to get it from VLC
             if (coverPath == null || !cacheFile.exists())
diff --git a/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java b/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
index a0cf59e..8810408 100644
--- a/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java
@@ -95,7 +95,7 @@ public class HttpImageLoader implements Callbacks {
     }
 
     @Nullable
-    public static Bitmap downloadBitmap(String imageUrl) {
+    public static Bitmap getBitmapFromIconCache(String imageUrl) {
         if (iconsMap.containsKey(imageUrl)) {
             Bitmap bd = iconsMap.get(imageUrl).get();
             if (bd != null) {
@@ -103,8 +103,15 @@ public class HttpImageLoader implements Callbacks {
             } else
                 iconsMap.remove(imageUrl);
         }
+        return null;
+    }
+
+    @Nullable
+    public static Bitmap downloadBitmap(String imageUrl) {
         HttpURLConnection urlConnection = null;
-        Bitmap icon = null;
+        Bitmap icon = getBitmapFromIconCache(imageUrl);
+        if (icon != null)
+            return icon;
         try {
             URL url = new URL(imageUrl);
             if (url.getPort() <= 0)
-- 
2.9.3



More information about the Android mailing list