How to create a video preview in android?
Asked Answered
P

2

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.

Pearliepearline answered 12/8, 2011 at 8:43 Comment(1)
Have you tried using the thumbnail utilsCampaign
A
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);
Ailin answered 31/8, 2012 at 12:49 Comment(2)
How does Samsung and others make short video previews that play as you view many videos?Wilkinson
FOR VIDEO TO PLAY FROM URLCoatbridge
P
1

This example works for blonde.mp4 file:

String videoFile = "/sdcard/blonde.mp4";
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFile, MediaStore.Images.Thumbnails.MINI_KIND);
Paxton answered 12/6, 2017 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.