I want to select a video from my Gallery. It's working fine. But now I want to display a Bitmap, as a thumbnail.I tried this code and it's not working, it always says: NullPointerException
Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail(uri.getPath, MediaStore.Video.Thumbnails.MICRO_KIND);
This is all in an onActivityResult()
.
How can I get the Bitmap from the video Uri??
Thanks for your help
This works for me: Bitmap thumb = ThumbnailUtils. createVideoThumbnail(filePath, Thumbnails. MINI_KIND);
You can take a screenshot from your video that best explains its contents, or you can use a tool like Photoshop or Canva to overlay text or icons on the image. To make a screen capture on a PC, use the Windows Snipping Tool. For Mac users, hit Command+Shift+4 to select the part of your screen you want to capture.
Many of the application are using the Glide library for loading the Image and Video thumbnail. You can download the Glide Library from here and alternatively, you can include the library directly in your app using Gradle.
In the latest API 24, you may face some issues if you stick with an approach in the accepted answer.
for example in this line int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
sometimes I got W/System.err: java.lang.IllegalArgumentException: column '_data' does not exist
error message.
also in the latest API, you may get SecurityException if you deal with widgets or shared content. Keep that in mind.
As for the video thumbnail from Uri - I use an approach which utilizes MediaMetadataRetriever, thus you don't need to get String filePath:
MediaMetadataRetriever mMMR = new MediaMetadataRetriever();
mMMR.setDataSource(context, videoUri);
bmp = mMMR.getFrameAtTime();
Hope this helps
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