저는 지원되는 비디오 캡처 응용 프로그램을 제작하고 있지만 비디오를 캡처하고 해당 비디오를 캡처하여 기본 카메라 폴더에 저장하지만 그 결과 코드는 -1입니다. 다음 코드를 사용하고 있습니다.누우 가트 (Nougat)에서의 비디오 캡쳐?
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
제거하고 시도해 보겠지만 동영상 및 경로가 나에게 돌아 오지 않으며 오류가 발생하지 않습니다. – Kuldeep
그러면 질문을 편집하고 ** 문제가있는 ** ** 당신의 onActivityResult() 메소드와 당신이 상상하고있는'Uri' ("path"가 아닌)를 어떻게 사용하는지 보여줘야합니다 돌아 오기. – CommonsWare