[Android] AudioUtil: add getCover(MediaList) helpers

Thomas Guillem git at videolan.org
Tue Oct 6 18:32:34 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Oct  6 17:53:15 2015 +0200| [18588230df02e814233593d604f2ddb603c211fb] | committer: Thomas Guillem

AudioUtil: add getCover(MediaList) helpers

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

 .../src/org/videolan/vlc/gui/audio/AudioUtil.java  |   38 +++++++++++++-------
 1 file changed, 25 insertions(+), 13 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 fb8641d..aee7780 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -395,6 +395,30 @@ public class AudioUtil {
         return cover;
     }
 
+    public static Bitmap getCover(Context context, ArrayList<MediaWrapper> list, int width, boolean fromMemCache) {
+        Bitmap cover = null;
+        LinkedList<String> testedAlbums = new LinkedList<String>();
+        for (MediaWrapper media : list) {
+            if (media.getAlbum() != null && testedAlbums.contains(media.getAlbum()))
+                continue;
+
+            cover = fromMemCache ? AudioUtil.getCoverFromMemCache(context, media, width) : AudioUtil.getCover(context, media, width);
+            if (cover != null)
+                break;
+            else if (media.getAlbum() != null)
+                testedAlbums.add(media.getAlbum());
+        }
+        return cover;
+    }
+
+    public static Bitmap getCoverFromMemCache(Context context, ArrayList<MediaWrapper> list, int width) {
+        return getCover(context, list, width, true);
+    }
+
+    public static Bitmap getCover(Context context, ArrayList<MediaWrapper> list, int width) {
+        return getCover(context, list, width, false);
+    }
+
     public static class AudioCoverFetcher implements Callable<Bitmap> {
 
         ArrayList<MediaWrapper> list;
@@ -407,19 +431,7 @@ public class AudioUtil {
 
         @Override
         public Bitmap call() throws Exception {
-            Bitmap cover = null;
-            LinkedList<String> testedAlbums = new LinkedList<String>();
-            for (MediaWrapper media : list) {
-                if (media.getAlbum() != null && testedAlbums.contains(media.getAlbum()))
-                    continue;
-
-                cover = AudioUtil.getCover(context, media, 64);
-                if (cover != null)
-                    break;
-                else if (media.getAlbum() != null)
-                    testedAlbums.add(media.getAlbum());
-            }
-            return cover;
+            return getCover(context, list, 64);
         }
     }
 }



More information about the Android mailing list