[Android] don't retry when there is no cover by storing an empty cache cover

Sébastien Toque git at videolan.org
Sun Oct 14 18:39:34 CEST 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun Oct 14 18:36:10 2012 +0200| [a572b927abd5ae4390e9c802fb9749b14608fc0b] | committer: Sébastien Toque

don't retry when there is no cover by storing an empty cache cover

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

 .../src/org/videolan/vlc/gui/audio/AudioUtil.java      |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 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 c9c2d52..1a189dc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -175,7 +175,13 @@ public class AudioUtil {
             // try to load from cache
             int hash = MurmurHash.hash32(media.getArtist()+media.getAlbum());
             cachePath = COVER_DIR + (hash >= 0 ? "" + hash : "m" + (-hash)) + "_" + width;
-            cover = readBitmap(cachePath);
+            File cacheFile = new File(cachePath);
+            if (cacheFile != null && cacheFile.exists()) {
+                if (cacheFile.length() > 0)
+                    cover = readBitmap(cachePath);
+                else
+                    return null;
+            }
             if (cover != null)
                 return cover;
 
@@ -195,8 +201,7 @@ public class AudioUtil {
                 cover = Util.scaleDownBitmap(context, cover, width);
 
             // store cover into cache
-            if (cover != null)
-                writeBitmap(cover, cachePath);
+            writeBitmap(cover, cachePath);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -209,7 +214,8 @@ public class AudioUtil {
         try {
             File file = new File(path);
             out = new BufferedOutputStream(new FileOutputStream(file), 4096);
-            bitmap.compress(CompressFormat.JPEG, 90, out);
+            if (bitmap != null)
+                bitmap.compress(CompressFormat.JPEG, 90, out);
         } catch (Exception e) {
             Log.e(TAG, "writeBitmap failed : "+ e.getMessage());
         } finally {
@@ -220,8 +226,6 @@ public class AudioUtil {
     }
 
     private static Bitmap readBitmap(String path) {
-        File file = new File(path);
-        if (file == null || !file.exists()) return null;
         return BitmapFactory.decodeFile(path);
     }
 }



More information about the Android mailing list