[Android] Add bitmap caching to Media

Ludovic Fauvet git at videolan.org
Mon Oct 15 19:16:55 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Oct 15 19:11:36 2012 +0200| [24a26d518eec6b263fdb6407960001dda96a96ac] | committer: Ludovic Fauvet

Add bitmap caching to Media

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

 vlc-android/src/org/videolan/vlc/Media.java |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index e0807f6..18bf3cb 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -270,10 +270,21 @@ public class Media implements Comparable<Media> {
     }
 
     public Bitmap getPicture() {
+        // mPicture is not null only if passed through
+        // the ctor which is deprecated by now.
         if (mPicture == null) {
-            /* Lazy loading: slower but memory efficient */
-            Context c = VLCApplication.getAppContext();
-            return DatabaseManager.getInstance(c).getPicture(c, mLocation);
+            BitmapCache cache = BitmapCache.getInstance();
+            Bitmap picture = cache.getBitmapFromMemCache(mLocation);
+            if (picture == null) {
+                /* Not in memcache:
+                 * serving the file from the database and
+                 * adding it to the memcache for later use.
+                 */
+                Context c = VLCApplication.getAppContext();
+                picture = DatabaseManager.getInstance(c).getPicture(c, mLocation);
+                cache.addBitmapToMemCache(mLocation, picture);
+            }
+            return picture;
         } else {
             return mPicture;
         }



More information about the Android mailing list