[Android] Pass image width to thumbnail provider
Geoffrey Métais
git at videolan.org
Wed May 16 10:42:11 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 16 10:21:50 2018 +0200| [55265e3f1c6ea15e41360ba456d02ec4930a2104] | committer: Geoffrey Métais
Pass image width to thumbnail provider
> https://code.videolan.org/videolan/vlc-android/commit/55265e3f1c6ea15e41360ba456d02ec4930a2104
---
.../org/videolan/vlc/gui/helpers/ImageLoader.kt | 8 +++-----
.../org/videolan/vlc/util/ThumbnailsProvider.java | 22 ++++++++++------------
2 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index d31ce94b5..837817841 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -69,11 +69,9 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
binding?.removeOnRebindCallback(rebindCallbacks!!)
}
-private suspend fun obtainBitmap(item: MediaLibraryItem, width: Int) : Bitmap? {
- return withContext(VLCIO) {
- if (item.itemType == MediaLibraryItem.TYPE_MEDIA) ThumbnailsProvider.getMediaThumbnail(item as MediaWrapper)
- else AudioUtil.readCoverBitmap(Uri.decode(item.artworkMrl), width)
- }
+private suspend fun obtainBitmap(item: MediaLibraryItem, width: Int) = withContext(VLCIO) {
+ if (item.itemType == MediaLibraryItem.TYPE_MEDIA) ThumbnailsProvider.getMediaThumbnail(item as MediaWrapper, width)
+ else AudioUtil.readCoverBitmap(Uri.decode(item.artworkMrl), width)
}
@MainThread
diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
index d527d6ccb..97bf995d7 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
@@ -12,7 +12,6 @@ import android.text.TextUtils;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
-import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.BitmapCache;
@@ -32,14 +31,13 @@ public class ThumbnailsProvider {
private static File appDir;
private static String cacheDir;
- private static final int sImageWidth = VLCApplication.getAppResources().getDimensionPixelSize(VLCApplication.showTvUi() ? R.dimen.tv_grid_card_thumb_width : R.dimen.grid_card_thumb_width);
private static final int MAX_IMAGES = 4;
@WorkerThread
- public static Bitmap getMediaThumbnail(final MediaWrapper item) {
- if (item.getType() == MediaWrapper.TYPE_GROUP) return ThumbnailsProvider.getComposedImage((MediaGroup) item);
- if (item.getType() == MediaWrapper.TYPE_VIDEO && TextUtils.isEmpty(item.getArtworkMrl())) return getVideoThumbnail(item);
- else return AudioUtil.readCoverBitmap(Uri.decode(item.getArtworkMrl()), sImageWidth);
+ public static Bitmap getMediaThumbnail(final MediaWrapper item, int width) {
+ if (item.getType() == MediaWrapper.TYPE_GROUP) return ThumbnailsProvider.getComposedImage((MediaGroup) item, width);
+ if (item.getType() == MediaWrapper.TYPE_VIDEO && TextUtils.isEmpty(item.getArtworkMrl())) return getVideoThumbnail(item, width);
+ else return AudioUtil.readCoverBitmap(Uri.decode(item.getArtworkMrl()), width);
}
public static String getMediaCacheKey(boolean isMedia, MediaLibraryItem item) {
@@ -53,14 +51,14 @@ public class ThumbnailsProvider {
}
@WorkerThread
- private static Bitmap getVideoThumbnail(final MediaWrapper media) {
+ private static Bitmap getVideoThumbnail(final MediaWrapper media, int width) {
final String filePath = media.getUri().getPath();
if (appDir == null) appDir = VLCApplication.getAppContext().getExternalFilesDir(null);
final boolean hasCache = appDir != null && appDir.exists();
final String thumbPath = getMediaCacheKey(true, media);
final Bitmap cacheBM = hasCache ? BitmapCache.getInstance().getBitmapFromMemCache(thumbPath) : null;
if (cacheBM != null) return cacheBM;
- if (hasCache && new File(thumbPath).exists()) return readCoverBitmap(thumbPath, sImageWidth);
+ if (hasCache && new File(thumbPath).exists()) return readCoverBitmap(thumbPath, width);
if (media.isThumbnailGenerated()) return null;
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
if (bitmap != null) {
@@ -76,12 +74,12 @@ public class ThumbnailsProvider {
}
@WorkerThread
- private static Bitmap getComposedImage(MediaGroup group) {
+ private static Bitmap getComposedImage(MediaGroup group, int width) {
final BitmapCache bmc = BitmapCache.getInstance();
final String key = "group:"+group.getTitle();
Bitmap composedImage = bmc.getBitmapFromMemCache(key);
if (composedImage == null) {
- composedImage = composeImage(group);
+ composedImage = composeImage(group, width);
if (composedImage != null) bmc.addBitmapToMemCache(key, composedImage);
}
return composedImage;
@@ -91,11 +89,11 @@ public class ThumbnailsProvider {
* @param group The MediaGroup instance
* @return a Bitmap object
*/
- private static Bitmap composeImage(MediaGroup group) {
+ private static Bitmap composeImage(MediaGroup group, int imageWidth) {
final Bitmap[] sourcesImages = new Bitmap[Math.min(MAX_IMAGES, group.size())];
int count = 0, minWidth = Integer.MAX_VALUE, minHeight = Integer.MAX_VALUE;
for (MediaWrapper media : group.getAll()) {
- final Bitmap bm = getVideoThumbnail(media);
+ final Bitmap bm = getVideoThumbnail(media, imageWidth);
if (bm != null) {
int width = bm.getWidth();
int height = bm.getHeight();
More information about the Android
mailing list