title: How to use MediaRecorder to capture video on Android?
body: <p>I would like to create a short video clip using the <code>MediaRecorder</code>, but I don't know how to use it.</p>
  
  <p>In my manifest file I added these permissions before the application-end-tag:</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.RECORD_VIDEO" /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>And I create a <code>MediaRecorder</code> with this code when the user press a button:</p>
  
  <pre><code>    private void startRecording() {
      mRecorder = new MediaRecorder();
      mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      mRecorder.setOutputFile("myvideo.mpeg4");
  
      try {
          mRecorder.prepare();
      } catch (IOException e) {
  
      }
      mRecorder.start();
  }
  </code></pre>
  
  <p>But when I run that code I get a "Force close - The application has stopped unexpectedly. Please try again" message. How should I use <code>MediaRecorder</code> and how can I debug my application to see what causes the exception? Do I need to add any other user permissions to my manifest file?</p>