我创建支持牛轧糖的视频捕获应用程序,但我捕获视频,该视频捕获并保存到默认相机文件夹,但结果代码为-1。我正在使用以下代码。视频采集牛轧糖?
public void startRecordingVideo() {
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File mediaFile = new File(
Environment.getExternalStorageDirectory().getAbsolutePath() + "/myvideo.mp4");
videoUri = Uri.fromFile(mediaFile);
//intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, VIDEO_CAPTURE);
} else {
Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show();
}
}
我在这里
if (requestCode == VIDEO_CAPTURE) {
//if (resultCode == RESULT_OK) {
int width = 0, DisplayWidth = 0;
//int height = 0, DisplayHeight = 0;
if (new File(Constants.APP_PATH + "/myvideo1.mp4").exists()) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(Constants.APP_PATH + "/myvideo1.mp4");
Bitmap bmp = retriever.getFrameAtTime();
width = bmp.getHeight();
VideoPath = Constants.APP_PATH + "/myvideo1.mp4";
DisplayMetrics displaymetrics = new DisplayMetrics();
MainActivity.this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
DisplayWidth = displaymetrics.widthPixels;
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int VideoDuration = Integer.parseInt(time);
if (width >= DisplayWidth * 1.5 && VideoDuration <= Constants.VIDEO_UPPER_LIMIT) {
new ResizeVideoTask(VideoPath).execute();
} else if (VideoDuration > Constants.VIDEO_UPPER_LIMIT) {
showTimeDialog();
} else {
File afile = new File(VideoPath);
String path = Constants.APP_PATH + "/myvideo.mp4";
File destfile = new File(path);
if (destfile.exists()) {
destfile.delete();
}
copyFile(new FileInputStream(afile),new FileOutputStream(destfile));
Intent switchIntent = new Intent(MainActivity.this,VideoActivity.class);
switchIntent.putExtra("URI", Uri.fromFile(destfile).toString());
switchIntent.putExtra("FILE_PATH", path);
startActivity(switchIntent);
}
retriever.release();
}
} else if (resultCode == RESULT_CANCELED) {
} else {
//}
}
你的结果是['RESULT_OK'](https://developer.android.com/reference/android/app/Activity.html#RESULT_OK)。为什么这是个问题? – CommonsWare
我将删除它,并尝试但videouri和路径不会返回给我并生成未找到错误。 – Kuldeep
然后,也许你应该编辑你的问题,并显示**是有问题的代码:你的'onActivityResult()'方法以及你如何尝试使用你所假设的'Uri'(而不是“路径”)去取回。 – CommonsWare