我发送了启动摄像机的意图
PackageManager pm = getPackageManager();
if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)){
Intent video = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File tempDir= new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "BCA");
if(!tempDir.exists())
{
if(!tempDir.mkdir()){
Toast.makeText(this, "Please check SD card! Image shot is impossible!", Toast.LENGTH_SHORT).show();
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US).format(new Date());
File mediaFile = new File(tempDir.getPath() + File.separator +
"VIDEO_"+ timeStamp + ".mp4");
Uri videoUri = Uri.fromFile(mediaFile);
video.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
video.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(video, VIDEO_REQUEST);
}else{
Toast.makeText(this, "This device does not have a rear facing camera",Toast.LENGTH_SHORT).show();
}
我拍摄了一个视频,它被正确存储,当onActivityResult
被解雇时,我使用意图获取uri
其存储位置以创建位图
这是 uri 的一个例子file:///storage/emulated/0/Pictures/BCA/VIDEO_20131227_145043.mp4
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(intent.getDataString(), MediaStore.Video.Thumbnails.MICRO_KIND);
但位图每次都是空的。因此,由于文档说May return null if the video is corrupt or the format is not supported
我检查了目录中的视频,并且它播放良好,而且它的.mp4
文件受支持,所以我在这里做错了什么?