我送的意圖,啓動攝像機從視頻文件創建縮略圖返回null位圖
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);
的一個例子,但該位圖是每次都是null。所以,由於文檔說May return null if the video is corrupt or the format is not supported
我檢查目錄中的視頻,它播放罰款加上其.mp4
文件支持,所以我在這裏做錯了什麼?
嗨,我希望你解決了這個問題。請分享如何。我也面臨同樣的問題 – 2014-04-02 09:14:35