How to create a video preview in android?

只愿长相守 提交于 2019-11-27 10:57:31

问题


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:


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:


This example works for blonde.mp4 file:

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


来源:https://stackoverflow.com/questions/7037630/how-to-create-a-video-preview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!