Search code examples
androidandroid-intentvideo-thumbnails

How to Get Video Thumbnail from onActivityResult Intent?


Below is my code, I'm getting a null from ThumbnailUtils.createVideoThumbnail

Intent takePicture = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
takePicture.setType("video/*");
startActivityForResult(takePicture, 4);

My OnResultActivity Code for Video File Pick Intent:

if(requestCode == 4) {
    Uri selectedVideoUri = data.getData();
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(selectedVideoUri.getPath(), MediaStore.Video.Thumbnails.MINI_KIND);
    Log.i("Video URI, ", String.valueOf(bitmap));
}

and also please help me how to get thumbnail from recorded video intent

Intent takeVideo = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideo, REQUEST_VIDEO_CAPTURE);

Solution

  • after some research I noticed that the file path shouldn't be uri

    you should have something like this

    final String noturipath = getRealPathFromUri();
    
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(noturipath, MediaStore.Video.Thumbnails.MICRO_KIND);
    

    then create a method

        public string getRealPathFromUri (final Uri content)
        {
     // get intent from activity and added it here
    
        Uri uri;
        String stringUri;
        stringUri = uri.toString();
        }