Get Video Thumbnail from Uri

前端 未结 7 1236
遇见更好的自我
遇见更好的自我 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:27

    1. createVideoThumbnail() needs the file path, not the content uri.
    2. The file path requires external read permissions.

    If you're getting null responses, it may be from using the content uri (though the assumption in ThumbnailsUtils.java is of a corrupt video file). When I fixed that, then I was getting permissions errors.

    I was able to get the file path from the content uri using the video's ID like this:

    val selection = MediaStore.Video.Media._ID + " = $id"
    val cursor = 
    this.contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, 
    selection, null, null)      
    

    And then continue on with the cursor as in the other answers in SO.

    Docs for contentResolver.query()

提交回复
热议问题