检索视频的缩略图 [英] Retrieve a thumbnail of a video

查看:203
本文介绍了检索视频的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出申请为呈现最佳电影预告片。我想显示每个视频的缩略图网格视图,然后单击它们打开一个新的活动,播放视频。

I'm trying to make an application for showing the best movie trailers. I'd like to show a grid view with the thumbnails of each video and then clicking them open a new Activity for playing the video.

由于视频的那一刻,我怎么能检索缩略图?如果这是复杂的第一帧过于足够多。谢谢

Given a moment of the video, how can I retrieve the thumbnail? If that is complicated the first frame is enought too. Thanks

推荐答案

如果您使用的是API 2.0或更新版本,这将正常工作。

If you are using API 2.0 or newer this will work.

要获取的视频ID:

String[] proj = {
    MediaStore.Video.Media._ID,
        MediaStore.Video.Media.DISPLAY_NAME,
    MediaStore.Video.Media.DATA
};

Cursor cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
                                    proj, MediaStore.Video.Media.DISPLAY_NAME+"=?",new String[] {"name.mp4"}, null);
cursor.moveToFirst()
id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));

要获得视频的缩略图:

ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);

修改的:

EDIT:

如果你是在Android-8(升级Froyo)或以上,你可以使用<一个href=\"http://developer.android.com/reference/android/media/ThumbnailUtils.html#createVideoThumbnail%28java.lang.String,%20int%29\"相对=nofollow> ThumbnailUtils.createVideoThumbnail 从视频路径:

If you are on android-8 (Froyo) or above, you can use ThumbnailUtils.createVideoThumbnail from video path:

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
    MediaStore.Images.Thumbnails.MINI_KIND);

希望它帮助!

这篇关于检索视频的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆