[Android] Cover for video files
Geoffrey Métais
git at videolan.org
Wed Mar 25 17:14:56 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 25 17:08:32 2015 +0100| [f24de5c58835be3604a7ab585ec520dc80d3f19d] | committer: Geoffrey Métais
Cover for video files
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=f24de5c58835be3604a7ab585ec520dc80d3f19d
---
vlc-android/src/org/videolan/vlc/Thumbnailer.java | 2 ++
.../videolan/vlc/gui/video/VideoListAdapter.java | 2 --
.../src/org/videolan/vlc/util/BitmapUtil.java | 36 ++++++++++++++++++--
3 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/Thumbnailer.java b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
index 2097be8..22715fb 100644
--- a/vlc-android/src/org/videolan/vlc/Thumbnailer.java
+++ b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
@@ -169,6 +169,8 @@ public class Thumbnailer implements Runnable {
mVideoBrowser.sendTextInfo(String.format("%s %s", mPrefix, item.getFileName()), count, total);
}
count++;
+ if (item.getArtworkURL() != null)
+ continue; //no need for thumbnail, we have a cover
int width = (int) (120 * mDensity);
int height = (int) (75 * mDensity);
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 815e727..bc2f024 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -35,8 +35,6 @@ import org.videolan.vlc.util.Util;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
-import android.support.annotation.Nullable;
-import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
diff --git a/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java b/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
index cdf3dd7..377f3c7 100644
--- a/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
+++ b/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
@@ -26,6 +26,8 @@ import org.videolan.vlc.VLCApplication;
import android.content.Context;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
public class BitmapUtil {
public final static String TAG = "VLC/Util/BitmapUtil";
@@ -79,8 +81,7 @@ public class BitmapUtil {
return bitmap;
}
- public static Bitmap getPictureFromCache(MediaWrapper media)
- {
+ public static Bitmap getPictureFromCache(MediaWrapper media) {
// mPicture is not null only if passed through
// the ctor which is deprecated by now.
Bitmap b = media.getPicture();
@@ -93,7 +94,9 @@ public class BitmapUtil {
* adding it to the memcache for later use.
*/
Context c = VLCApplication.getAppContext();
- picture = MediaDatabase.getInstance().getPicture(c, media.getLocation());
+ picture = readCoverBitmap(media.getArtworkURL());
+ if (picture == null)
+ picture = MediaDatabase.getInstance().getPicture(c, media.getLocation());
cache.addBitmapToMemCache(media.getLocation(), picture);
}
return picture;
@@ -101,4 +104,31 @@ public class BitmapUtil {
return b;
}
}
+
+ private static Bitmap readCoverBitmap(String path) {
+ if (path == null)
+ return null;
+ String uri = Uri.decode(path);
+ if (uri.startsWith("file://"))
+ uri = uri.substring(7);
+ Bitmap cover = null;
+ BitmapFactory.Options options = new BitmapFactory.Options();
+
+ /* Get the resolution of the bitmap without allocating the memory */
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(uri, options);
+
+ if (options.outWidth > 0 && options.outHeight > 0) {
+ options.inJustDecodeBounds = false;
+
+ // Decode the file (with memory allocation this time)
+ cover = BitmapFactory.decodeFile(uri, options);
+
+ if (cover != null) {
+ cover = Bitmap.createScaledBitmap(cover, options.outWidth, options.outHeight, false);
+ }
+ }
+
+ return cover;
+ }
}
More information about the Android
mailing list