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

Geoffrey Métais geoffrey.metais at gmail.com
Mon Nov 28 15:27:14 CET 2016


LGTM

On Sun, Nov 27, 2016 at 9:06 PM Marc K <morckx at gmail.com> wrote:

> 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
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20161128/7e4b51d4/attachment.html>


More information about the Android mailing list