Commit 55265e3f authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Pass image width to thumbnail provider

parent 3d776270
......@@ -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
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment