Gagan
Gagan

Reputation: 755

Switching from back camera to front camera for video recording is not working

Back camera is working fine but,when we switch from back to front camera ,it crashes(in case of video recording using MediaRecorder ).... it showing error which i show in log !!

enter image description here

Here is my code :

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");


  }
 }

and for initialize i use

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

Upvotes: 0

Views: 959

Answers (2)

Gagan
Gagan

Reputation: 755

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

Upvotes: 0

Preethi Rao
Preethi Rao

Reputation: 5175

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

try adding this part of code

Upvotes: 2

Related Questions