20

I have a video file in my sdcard. I would like to show a preview of this video in my ImageView . Please let me know how to do this in Android. Thank you for your help and time.

1
  • 1
    Have you tried using the thumbnail utils Aug 12, 2011 at 9:38

2 Answers 2

45

If you use API level 8 and above. You can create preview of a video like this:

String videoFile = "/sdcard/blonde.mp4";
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFile,
        MediaStore.Images.Thumbnails.MINI_KIND);

Now you can show it in an ImageView:

ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
imageView.setImageBitmap(thumbnail);

Or you can set it to a VideoView as a background, so that it is shown as a first video frame before the video starts playing:

VideoView video = (VideoView) findViewById(R.id.my_video_view);
BitmapDrawable bitmapDrawable = new BitmapDrawable(thumbnail);
video.setBackgroundDrawable(bitmapDrawable);
2
  • 1
    How does Samsung and others make short video previews that play as you view many videos? Apr 12, 2014 at 22:13
  • FOR VIDEO TO PLAY FROM URL
    – Prasad
    Oct 21, 2014 at 12:06
1

This example works for blonde.mp4 file:

String videoFile = "/sdcard/blonde.mp4";
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFile, MediaStore.Images.Thumbnails.MINI_KIND);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.