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

Marc K morckx at gmail.com
Mon Nov 7 10:04:41 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>
---
 vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java |  7 +++++--
 vlc-android/src/org/videolan/vlc/util/HttpImageLoader.java  | 11 +++++++++--
 2 files changed, 14 insertions(+), 4 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..022387a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
@@ -42,6 +42,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;
@@ -322,8 +323,6 @@ public class AudioUtil {
                 if (cacheFile.exists()) {
                     if (cacheFile.length() > 0)
                         coverPath = cachePath;
-                    else
-                        return null;
                 }
             }
 
@@ -342,6 +341,10 @@ public class AudioUtil {
             // read (and scale?) the bitmap
             cover = readCoverBitmap(coverPath, width);
 
+            // as last resort try to get the cover from the icon cache
+            if (cover == null && media.getArtworkURL() != null)
+                cover = HttpImageLoader.getBitmapFromIconCache(media.getArtworkURL());
+
             // store cover into both cache
             if (cachePath != null) {
                 writeBitmap(cover, cachePath);
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