Fixed video thumbnail generation for older Android versions

pull/214/head
M66B 11 months ago
parent debca5d675
commit 13debc2e9c

@ -33,6 +33,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Size; import android.util.Size;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -148,12 +149,17 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
} }
} else if (type != null && type.startsWith("video/")) { } else if (type != null && type.startsWith("video/")) {
try { try {
Bitmap bm = ThumbnailUtils.createVideoThumbnail(file, new Size(max, max), null); // https://developer.android.com/reference/android/media/ThumbnailUtils
Bitmap bm;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
bm = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND);
else
bm = ThumbnailUtils.createVideoThumbnail(file, new Size(max, max), null);
if (bm == null) if (bm == null)
return null; throw new IllegalArgumentException("Thumbnail generation failed");
return new BitmapDrawable(context.getResources(), bm); return new BitmapDrawable(context.getResources(), bm);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.i(ex); Log.w(ex);
return context.getDrawable(R.drawable.twotone_ondemand_video_24); return context.getDrawable(R.drawable.twotone_ondemand_video_24);
} }
} else { } else {

Loading…
Cancel
Save