我正在使用自定义相机在我的Android应用中录制20个最长秒视频。 我想在保存之前自动预览录制的视频(在手机或服务器上)。我知道我必须使用VideoView,但我找不到。
我想停止录制,如果它超过20秒并自动启动预览(VideoView)或用户更快停止捕获。 使用2个按钮“删除”和“确定”。
任何人都知道怎么做?我是否必须创建新活动并使用意图?
以下是录制视频的当前代码:
private boolean prepareVideoRecorder(){
// 1. Open Camera
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
//Set video duration to 20 seconds max
int clipsDuration = 20000;
mMediaRecorder.setMaxDuration(clipsDuration);
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_BACK){
mMediaRecorder.setOrientationHint(90);
} else {
mMediaRecorder.setOrientationHint(270);
}
// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
非常感谢你的帮助!