Trying to get thumbnails from a video. Prior to API 29, this was managed using MediaStore.Images.Thumbnails. Code example
Bitmap bitmapThumbnail = ThumbnailU
//You can use this
val bitmapThumbnail = ThumbnailUtils.createVideoThumbnail(
File(filePath),
Size(120, 120),
null)
createVideoThumbnail
was changed from:
public static Bitmap createVideoThumbnail (String filePath, int kind)
to
public static Bitmap createVideoThumbnail (File file, Size size, CancellationSignal signal)
So, the example you have provided in your question, will change to the following:
Size mSize = new Size(96,96);
CancellationSignal ca = new CancellationSignal();
Bitmap bitmapThumbnail = ThumbnailUtils.createVideoThumbnail(new File(videoArrayList.get(position).getPath()), mSize, ca);
You can use CancellationSignal
to cancel the creation of the Bitmap
by calling ca.cancel();
.
The Size
value depends on the size of Bitmap
you want:
Size: The target area on the screen where this thumbnail will be shown. This is passed to the provider as EXTRA_SIZE to help it avoid downloading or generating heavy resources. This value cannot be null.
You can also use loadThumbnail
, which accepts a Uri
instead of a File
object, like this:
public Bitmap loadThumbnail (Uri uri, Size size, CancellationSignal signal)
So your code will then look like this:
Uri mUri = ...; // Your Uri
Size mSize = new Size(96,96);
CancellationSignal ca = new CancellationSignal();
Bitmap bitmapThumbnail = getContentResolver().loadThumbnail(mUri, mSize, ca);