我想从我的 Android 应用程序录制视频。像这样
File f = new File(Environment.getExternalStorageDirectory() + "/"
+ app.getBaseName());
if (!f.exists()) {
f.mkdir();
}
filename = "Video" + lastfile() + ".mp4";
File f1 = new File(Environment.getExternalStorageDirectory() + "/"
+ app.getBaseName(), filename);
Uri uri = Uri.fromFile(f1);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(intent, 222);
并在结果活动中
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 222) {
Log.v("log_tag", "Return to back 222" + resultCode);
if (resultCode == RESULT_OK) {
Log.v("log_tag", "Return to back");
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
Log.v("log_tag", "Return to back fury");
}
finish();
super.onActivityResult(requestCode, resultCode, data);
}
使用它,相机正在启动,然后我单击中间按钮开始录制,而不是单击左侧按钮停止并保存并且应用程序崩溃。
我在 onActivityResult 中打印了 resultCode 的值,它给了我 0。并且视频以给定的名称正确保存在给定的路径上。请帮我。