Search code examples
androidandroid-cameravideo-recordingfront-camera

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

Solution

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