When I get bitmap for mp4 file with: ThumbnailUtils.createVideoThumbnail(mediaFile.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
return null
Try this, May be you media file path was wrong. Use below method you will get exact path. Its working for me
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(getPath(outputFileUri),
MediaStore.Images.Thumbnails.MINI_KIND);
photo_Img.setImageBitmap(thumb);
/**
* Get file path
*/
public static String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = context.managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
I think you must set requires permission in AndroidManifest <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
File file = new File(filepath);
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
From android docs:
public static Bitmap createVideoThumbnail (String filePath, int kind)
Create a video thumbnail for a video. May return null if the video is corrupt or the format is not supported.
Hence, I guess you need to re-check the mp4 file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With