我使用意向相机录制视频。我在三星,HTC,LG和我的测试我的应用程序摩托罗拉设备它可以顺利运行,但在Nexus Phones上录制视频并且选择压缩文件后崩溃是我用来启动意图和获取视频录制文件的代码。
case R.id.camera_icon:
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
uri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
if (uri == null) {
// display an error
Toast.makeText(MainActivity.this, R.string.error_external_storage,
Toast.LENGTH_LONG).show();
} else {
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
// 0 = lowest res
startActivityForResult(videoIntent, RESULT_CODE_COMPRESS_VIDEO);
}
创建存储位置:
private Uri getOutputMediaFileUri(int mediaType) {
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
if (isExternalStorageAvailable()) {
// get the URI
// 1. Get the external storage directory
String appName = MainActivity.this.getString(R.string.app_name);
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
appName);
// 2. Create our subdirectory
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.e(TAG, "Failed to create directory.");
return null;
}
}
String path = mediaStorageDir.getPath() + File.separator;
if (mediaType == MEDIA_TYPE_IMAGE) {
mediaFile = new File(path + "thumb" + ".jpg");
} else if (mediaType == MEDIA_TYPE_VIDEO) {
mediaFile = new File(path + "video" + ".mp4");
} else {
return null;
}
Log.d(TAG, "File: " + Uri.fromFile(mediaFile));
// 5. Return the file's URI
return Uri.fromFile(mediaFile);
} else {
return null;
}
}