[Android] Fix thumbnail generation crash

Geoffrey Métais git at videolan.org
Mon Apr 29 10:31:06 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 29 10:29:47 2019 +0200| [c66d57057f27e705f79c0d3144246b4386aa9cae] | committer: Geoffrey Métais

Fix thumbnail generation crash

> https://code.videolan.org/videolan/vlc-android/commit/c66d57057f27e705f79c0d3144246b4386aa9cae
---

 .../src/org/videolan/vlc/util/ThumbnailsProvider.java  | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
index 6b81f9703..600ecc75d 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
@@ -8,6 +8,8 @@ import android.net.Uri;
 import android.provider.MediaStore;
 import android.text.TextUtils;
 
+import androidx.annotation.WorkerThread;
+
 import org.videolan.medialibrary.Medialibrary;
 import org.videolan.medialibrary.media.Folder;
 import org.videolan.medialibrary.media.MediaLibraryItem;
@@ -21,11 +23,10 @@ import org.videolan.vlc.media.MediaGroup;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import androidx.annotation.WorkerThread;
-
 import static org.videolan.medialibrary.Medialibrary.THUMBS_FOLDER_NAME;
 import static org.videolan.vlc.gui.helpers.AudioUtil.readCoverBitmap;
 
@@ -41,8 +42,7 @@ public class ThumbnailsProvider {
     @WorkerThread
     public static Bitmap getFolderThumbnail(final Folder folder, int width) {
         final List<MediaWrapper> media = Arrays.asList(folder.media(Folder.TYPE_FOLDER_VIDEO, Medialibrary.SORT_DEFAULT, true, 4, 0));
-        final Bitmap img = ThumbnailsProvider.getComposedImage("folder:"+folder.getTitle(), media, width);
-        return img;
+        return ThumbnailsProvider.getComposedImage("folder:"+folder.getTitle(), media, width);
     }
 
     @WorkerThread
@@ -105,22 +105,22 @@ public class ThumbnailsProvider {
      * @return a Bitmap object
      */
     private static Bitmap composeImage(List<MediaWrapper> mediaList, int imageWidth) {
-        final Bitmap[] sourcesImages = new Bitmap[Math.min(MAX_IMAGES, mediaList.size())];
+        final List<Bitmap> sourcesImages = new ArrayList<>();
         int count = 0, minWidth = Integer.MAX_VALUE, minHeight = Integer.MAX_VALUE;
         for (MediaWrapper media : mediaList) {
             final Bitmap bm = getVideoThumbnail(media, imageWidth);
             if (bm != null) {
                 int width = bm.getWidth();
                 int height = bm.getHeight();
-                sourcesImages[count++] = bm;
+                sourcesImages.add(bm);
                 minWidth = Math.min(minWidth, width);
                 minHeight = Math.min(minHeight, height);
-                if (count == MAX_IMAGES) break;
+                if (++count == MAX_IMAGES) break;
             }
         }
         if (count == 0) return null;
-        if (count == 1) return sourcesImages[0];
-        return composeCanvas(sourcesImages, count, minWidth, minHeight);
+        if (count == 1) return sourcesImages.get(0);
+        return composeCanvas(sourcesImages.toArray(new Bitmap[0]), count, minWidth, minHeight);
     }
 
     private static Bitmap composeCanvas(Bitmap[] sourcesImages, int count, int minWidth, int minHeight) {



More information about the Android mailing list