如何从onActivityResult Intent获取视频缩略图?

时间:2015-11-02 11:59:36

标签: android android-intent video-thumbnails

下面是我的代码,我从ThumbnailUtils.createVideoThumbnail获取null

Intent takePicture = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
takePicture.setType("video/*");
startActivityForResult(takePicture, 4);

我的OnResultActivity Code for Video File Pick Intent:

if(requestCode == 4) {
    Uri selectedVideoUri = data.getData();
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(selectedVideoUri.getPath(), MediaStore.Video.Thumbnails.MINI_KIND);
    Log.i("Video URI, ", String.valueOf(bitmap));
}

还请帮我如何从录制的视频意图中获取缩略图

Intent takeVideo = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideo, REQUEST_VIDEO_CAPTURE);

1 个答案:

答案 0 :(得分:0)

经过一些研究后,我注意到file path不应该是uri

你应该有这样的东西

element {
    border:none;
    background-image:none;
    background-color:transparent;
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow: none;
}

然后创建一个方法

final String noturipath = getRealPathFromUri();

Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(noturipath, MediaStore.Video.Thumbnails.MICRO_KIND);