Get Video Thumbnail from Uri

前端 未结 7 1248
遇见更好的自我
遇见更好的自我 2020-12-19 07:45

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 tired this code it\'s not working, it always says: NullPoi

7条回答
  •  渐次进展
    2020-12-19 08:31

    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

提交回复
热议问题