[Android] Thumbnail: if we can't create a thumbnail, store a byte and don' t retry anymore
Sébastien Toque
git at videolan.org
Fri Jun 22 23:53:33 CEST 2012
android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Jun 22 23:53:25 2012 +0200| [b6fcb617c6ab4ebe9436317245f12601350d7211] | committer: Sébastien Toque
Thumbnail: if we can't create a thumbnail, store a byte and don't retry anymore
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=b6fcb617c6ab4ebe9436317245f12601350d7211
---
.../src/org/videolan/vlc/DatabaseManager.java | 19 +++++++++++++------
vlc-android/src/org/videolan/vlc/Media.java | 10 ++++++++++
.../src/org/videolan/vlc/ThumbnailerManager.java | 4 +++-
.../videolan/vlc/gui/video/VideoListFragment.java | 2 +-
4 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/DatabaseManager.java b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
index ff5b4a0..bc9d6ab 100644
--- a/vlc-android/src/org/videolan/vlc/DatabaseManager.java
+++ b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
@@ -324,7 +324,7 @@ public class DatabaseManager {
if (cursor.moveToFirst()) {
do {
blob = cursor.getBlob(3);
- if (blob != null) {
+ if (blob != null && blob.length > 1) {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
String location = cursor.getString(11);
@@ -340,6 +340,7 @@ public class DatabaseManager {
cursor.getInt(8),
cursor.getInt(9),
cursor.getString(10));
+ media.setPictureParsed(blob != null);
medias.put(media.getLocation(), media);
picture = null;
@@ -382,7 +383,7 @@ public class DatabaseManager {
if (cursor.moveToFirst()) {
blob = cursor.getBlob(3);
- if (blob != null) {
+ if (blob != null && blob.length > 1) {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
media = new Media(context, location,
@@ -397,6 +398,7 @@ public class DatabaseManager {
cursor.getInt(8),
cursor.getInt(9),
cursor.getString(10));
+ media.setPictureParsed(blob != null);
}
cursor.close();
return media;
@@ -411,10 +413,15 @@ public class DatabaseManager {
ContentValues values = new ContentValues();
switch (col) {
case MEDIA_PICTURE:
- Bitmap picture = (Bitmap) object;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- picture.compress(Bitmap.CompressFormat.PNG, 100, out);
- values.put(MEDIA_PICTURE, out.toByteArray());
+ if (object != null) {
+ Bitmap picture = (Bitmap) object;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ picture.compress(Bitmap.CompressFormat.PNG, 100, out);
+ values.put(MEDIA_PICTURE, out.toByteArray());
+ }
+ else {
+ values.put(MEDIA_PICTURE, new byte[1]);
+ }
break;
default:
return;
diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 0018fe8..6e65777 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -95,6 +95,7 @@ public class Media implements Comparable<Media> {
private int mWidth = 0;
private int mHeight = 0;
private Bitmap mPicture;
+ private boolean mIsPictureParsed;
/**
* Create a new Media
@@ -221,6 +222,15 @@ public class Media implements Comparable<Media> {
DatabaseManager.mediaColumn.MEDIA_PICTURE,
p);
mPicture = p;
+ mIsPictureParsed = true;
+ }
+
+ public boolean isPictureParsed() {
+ return mIsPictureParsed;
+ }
+
+ public void setPictureParsed(boolean isParsed) {
+ mIsPictureParsed = isParsed;
}
public String getTitle() {
diff --git a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
index 6c8a350..e8d4d75 100644
--- a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
+++ b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
@@ -131,8 +131,10 @@ public class ThumbnailerManager extends Thread {
//Log.i(TAG, "create new bitmap for: " + item.getName());
byte[] b = mLibVlc.getThumbnail(item.getLocation(), width, height);
- if (b == null) // We were not able to create a thumbnail for this item.
+ if (b == null) {// We were not able to create a thumbnail for this item.
+ item.setPicture(mVideoListActivity.getActivity(), null);
continue;
+ }
thumbnail.copyPixelsFromBuffer(ByteBuffer.wrap(b));
thumbnail = Util.cropBorders(thumbnail, width, height);
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
index 631b78a..ff1bfe0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
@@ -246,7 +246,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
for (Media item : itemList) {
if (item.getType() == Media.TYPE_VIDEO) {
mVideoAdapter.add(item);
- if (item.getPicture() == null)
+ if (item.getPicture() == null && !item.isPictureParsed())
mThumbnailerManager.addJob(item);
}
}
More information about the Android
mailing list