Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 561
Vinod Avatar asked Aug 12 '11 08:08

Vinod


People also ask

What is video preview?

Video previews let you see a 3-second preview of a video before watching. When you hover over a video's thumbnail on your computer, or scroll past a video on mobile search, you'll see a 3-second preview. After the video preview plays, you'll see the video's thumbnail.

Which tool is used to display the thumbnail of a video in Android?

Many of the application are using the Glide library for loading the Image and Video thumbnail. You can download the Glide Library from here and alternatively, you can include the library directly in your app using Gradle.


2 Answers

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);
like image 84
petrsyn Avatar answered Sep 28 '22 03:09

petrsyn


This example works for blonde.mp4 file:

String videoFile = "/sdcard/blonde.mp4";
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFile, MediaStore.Images.Thumbnails.MINI_KIND);
like image 21
Chirag Navadiya Avatar answered Sep 28 '22 03:09

Chirag Navadiya