How do I get thumbnail of a video in android

Vipul Singh picture Vipul Singh · Jun 20, 2018 · Viewed 7.3k times · Source

I want some help in creating thumbnail of a video being recorded from my android phone and I got this code from this Link, and I modified this part of the code to generate the thumbnail but somehow the thumbnail is not being generated, so any help will be appreciated.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == VIDEO_CAPTURED) {
        videoFileUri = data.getData();
        if (videoFileUri != null) {
           Bitmap image= ThumbnailUtils.createVideoThumbnail(videoFileUri.toString(),MODE_APPEND);

 ImageView imageView=(ImageView)findViewById(R.id.image);
 imageView.setImageBitmap(image);
        }

        playVideoButton.setEnabled(true);
    }
}

Answer

Mayur Patel picture Mayur Patel · Jun 20, 2018

You can use glide. its automatically set thumb image of video.

Glide is also able to display the thumbnail of videos, as long as they're stored on the phone. Let's assume you get the file path by letting the user select a video: Based on this document https://futurestud.io/tutorials/glide-displaying-gifs-and-videos

String filePath = "/storage/emulated/0/Pictures/example_video.mp4";

Glide  
    .with(context)
    .asBitmap()
    .load(Uri.fromFile(new File(filePath)))
    .into(imageViewGifAsBitmap);