0

后置摄像头工作正常,但是,当我们从后置摄像头切换到前置摄像头时,它会崩溃(在使用 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);
4

2 回答 2

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;
            }
        }

尝试添加这部分代码

于 2015-04-13T06:34:35.070 回答
0

some times device go in onPause state ,i just re initialize everything in onResume method of the activity and it works..!

于 2015-04-13T10:37:16.407 回答