title: Unable to restart recording (MediaRecorder)
body: <p>I can't seem to start recording again in my app once I have stopped recording.</p>
  
  <p>Basically it seems like I'm not handling correctly the stopping process of the MediaRecorder so it can start over once I hit the "Capture Button" again.</p>
  
  <p>I know there is a lot of code to copy/paste, but I'd like to know what's wrong with mine.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public class MainActivity extends Activity implements SurfaceHolder.Callback {
  
      private MediaRecorder mediaRecorder = null;
      private MediaPlayer mediaPlayer = null;
      private String fileName = null;
      private boolean recording = false;
      private String auxDate;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          SurfaceView surface = (SurfaceView) findViewById(R.id.cam_surface);
          SurfaceHolder holder = surface.getHolder();
          holder.addCallback(this);
          holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          final Button btnCapture = (Button)findViewById(R.id.button_capture);
          final Button btnStop = (Button)findViewById(R.id.button_stop);
          btnCapture.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  try{
                  Time now = new Time();  
                  now.setToNow();
                  int auxforDate = 0;
                  auxforDate = now.year;
                  auxDate = Integer.toString(auxforDate);
                  auxforDate = now.month + 1;
                  auxDate = auxDate + "_" + Integer.toString(auxforDate);
                  auxforDate = now.monthDay;
                  auxDate = auxDate + "_" + Integer.toString(auxforDate);
                  auxforDate = now.hour;
                  auxDate = auxDate + "_" + Integer.toString(auxforDate);
                  auxforDate = now.minute;
                  auxDate = auxDate + "_" + Integer.toString(auxforDate);
                  auxforDate = now.second;
                  auxDate = auxDate + "_" + Integer.toString(auxforDate);
                  } catch (Exception e){ e.printStackTrace();
                  try {
                      throw e;
                  } catch (Exception e1) {
                      e1.printStackTrace();
                  }}
                  fileName = Environment.getExternalStorageDirectory() + "/MobiNanny/" + auxDate + ".mp4";
                  btnCapture.setEnabled(false);
                  btnStop.setEnabled(true);
                  prepareRecorder();
                  mediaRecorder.setOutputFile(fileName);
                  try {
                      mediaRecorder.prepare();
                  } catch (IllegalStateException e) {
                  } catch (IOException e) {
                  } mediaRecorder.start();
                  recording = true;
              }
          });
  
          btnStop.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  if(recording == true){
                      mediaRecorder.stop();
                      mediaRecorder.reset();
                      btnCapture.setEnabled(true);
                      btnStop.setEnabled(false);
                      recording = false;
                  } else {
                      //Agregar pop-up (Dialog) que diga "The device is not recording."
                  }
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
      public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
          // TODO Auto-generated method stub
  
      }
  
      public void surfaceCreated(SurfaceHolder holder) {
  
          if (mediaRecorder == null) {
              mediaRecorder = new MediaRecorder();
              mediaRecorder.setPreviewDisplay(holder.getSurface());
          }
          if (mediaPlayer == null) {
              mediaPlayer = new MediaPlayer();
              mediaPlayer.setDisplay(holder);
          }
  
      }
  
      public void surfaceDestroyed(SurfaceHolder holder) {
  
          mediaRecorder.release();
          mediaPlayer.release();      
      }
  
      public void prepareRecorder(){
  
          mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
          mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
          mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
          mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
          mediaRecorder.setVideoFrameRate(5);
          mediaRecorder.setVideoSize(320, 240);
          }
  }
  </code></pre>
  
  <p>Best Regards.</p>