title: Record Video using surface view android
body: <p>I have to create an android app in which i am trying to record video and capture image using surface view.
  Up to now i am able to capture video but facing problem in record video.
   My code for video recording is - </p>
  
  <pre><code>onCreate(){
        ..
       surfaceHolder = surfaceView.getHolder();
       surfaceHolder.addCallback(this);
       surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
       startRecording();
       .
       .
  }
  
  
  protected void startRecording() throws IOException
      {
          if(mCamera==null)
              mCamera = Camera.open();
  
           String filename;
           String path;
  
           path= Environment.getExternalStorageDirectory().getAbsolutePath().toString();
  
           Date date=new Date();
           filename="/rec"+date.toString().replace(" ", "_").replace(":", "_")+".mp4";
  
           File file=new File(path,filename);
  
          mrec = new MediaRecorder(); 
  
          mCamera.lock();
          mCamera.unlock();
  
  
          mrec.setCamera(mCamera);    
          mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
          mrec.setAudioSource(MediaRecorder.AudioSource.MIC);     
          mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
          mrec.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
          mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
          mrec.setPreviewDisplay(surfaceHolder.getSurface());
          mrec.setOutputFile(path+filename);
          mrec.setMaxDuration(10000); 
    }
         @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,int                height) {      
  
          Camera.Parameters parameters = mCamera.getParameters();      
          parameters.setPreviewSize(width, height);     
          try {
              mCamera.setPreviewDisplay(surfaceHolder);
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          mCamera.setParameters(parameters);       
          mCamera.startPreview(); 
  
      }
  </code></pre>
  
  <p>but app force close when onSurfaceChange method code is called at line -
  mCamera.setPreviewDisplay(surfaceHolder); with exception java.lang.RuntimeException: setParameters failed</p>
  
  <p>so how can i manage it so i can start video recording.
  Thanks in advance.</p>