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

Marc K git at videolan.org
Tue Nov 29 12:04:49 CET 2016


vlc-android | branch: master | Marc K <morckx at gmail.com> | Sun Nov 27 21:05:50 2016 +0100| [c8b1f083f620a771e33f3c97eef67295dbc82b78] | committer: Geoffrey Métais

Use the icon cache as additional source for cover art

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>

> https://code.videolan.org/videolan/vlc-android/commit/c8b1f083f620a771e33f3c97eef67295dbc82b78
---

 .../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)



More information about the Android mailing list