Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Video Thumbnail from Uri

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

like image 230
Zocker Bros Avatar asked May 22 '17 09:05

Zocker Bros


People also ask

How do I get the Uri video thumbnail?

This works for me: Bitmap thumb = ThumbnailUtils. createVideoThumbnail(filePath, Thumbnails. MINI_KIND);

How do I get the thumbnail from a video?

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.

Which tool is used to display the thumbnail of a video in Android?

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.


1 Answers

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

like image 133
Kirill Karmazin Avatar answered Nov 08 '22 00:11

Kirill Karmazin