我发送启动摄像机的意图
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
文件受支持,那么我在这里做错了什么?
你可以试试媒体元数据检索器 http://developer.android.com/reference/android/media/MediaMetadataRetriever.html or FFmpeg媒体元数据检索器 https://github.com/wseemann/FFmpegMediaMetadataRetriever。这是一个例子:
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(intent.getDataString());
Bitmap b = mmr.getFrameAtTime();
mmr.release();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)