后置摄像头工作正常但是,当我们从后置摄像头切换到前置摄像头时,它会崩溃(如果使用MediaRecorder进行视频录制)....它显示我在日志中显示的错误!!
这是我的代码:
private void start_work()
{
if(recording)
{
Log.v("LOGTAG", "Recording Stopped");
}
else
{
recording = true;
progress_relative_lay.setVisibility(View.VISIBLE);
button_capture.setVisibility(View.GONE);
//show_icon();
recorder.start();
Log.v("LOGTAG", "Recording Started");
}
}
并初始化我使用
recorder = new MediaRecorder();
recorder.setOrientationHint(result) ;
recorder.setPreviewDisplay(holder.getSurface());
if(usecamera)
{
camera.unlock();
recorder.setCamera(camera);
}
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(camcorderProfile);
答案 0 :(得分:2)
if (camera != null) {
throw new RuntimeException("camera already initialized");
}
Camera.CameraInfo info = new Camera.CameraInfo();
// Try to find a front-facing camera (e.g. for videoconferencing).
int numCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numCameras; i++) {
Camera.getCameraInfo(i, info);
//this will be front or back depending on the requirement
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
camera= Camera.open(i);
break;
}
}
尝试添加此部分代码
答案 1 :(得分:0)
有时设备进入onPause状态,我只是重新初始化活动的onResume方法中的所有内容并且它可以工作..!