Skip to content Skip to sidebar Skip to footer

How To Create A Video Preview In Android?

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.

Solution 1:

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

StringvideoFile="/sdcard/blonde.mp4";
Bitmapthumbnail= ThumbnailUtils.createVideoThumbnail(videoFile,
        MediaStore.Images.Thumbnails.MINI_KIND);

Now you can show it in an ImageView:

ImageViewimageView= (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:

VideoViewvideo= (VideoView) findViewById(R.id.my_video_view);
BitmapDrawablebitmapDrawable=newBitmapDrawable(thumbnail);
video.setBackgroundDrawable(bitmapDrawable);

Solution 2:

This example works for blonde.mp4 file:

StringvideoFile="/sdcard/blonde.mp4";
Bitmapthumbnail= ThumbnailUtils.createVideoThumbnail(videoFile, MediaStore.Images.Thumbnails.MINI_KIND);

Post a Comment for "How To Create A Video Preview In Android?"