title: MediaRecorder: start failed: -19
body: <p>I'm trying to understand how to record video with camera. But it's always crashes on starting recording. And I don't have any idea why it's happening. I don't need to use any preview for now, just record to a file. Here is the code</p>
  
  <pre><code>    public static final String TAG = "tag";
      Button recBut;
      private MediaRecorder rec;
      private Camera camera;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          releaseCamera();
          recBut = (Button) findViewById(R.id.rec);
  
          camera = Camera.open(0);
          prepareCamera(camera);
          recBut.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if (recBut.getText().toString().equalsIgnoreCase("start")) {
                      rec.start(); //logcat say that problem here
                      recBut.setText("RECING...");
                  } else {
                      rec.stop();
                      rec.reset();
                      rec.release();
                      rec = null;
                      recBut.setText("START");
                      releaseCamera();
                  }
              }
          });
      }
  
      private void prepareCamera(Camera camera) {
          List&lt;Camera.Size&gt; list = camera.getParameters().getSupportedVideoSizes();
          Log.i(TAG, "GENERAL SIZE - " + list.size());
          for (int i = 0; i &lt; list.size(); i++) {
              Log.i(TAG, "SIZE| width - " + list.get(i).width + " hight - " + list.get(i).height);
          }
          rec = new MediaRecorder();
          camera.getParameters().setRecordingHint(true);
          rec.setCamera(camera);
          rec.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
          rec.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
          rec.setOutputFormat(MediaRecorder.OutputFormat.WEBM);
          rec.setVideoSize(720, 1280);
          rec.setVideoFrameRate(24);
          rec.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
          rec.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
          //        rec.setProfile(CamcorderProfile.get(0, CamcorderProfile.QUALITY_HIGH));
          rec.setOutputFile(
                  Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_MOVIES + "/test.mp4");
          rec.setPreviewDisplay(null);
          try {
              rec.prepare();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private void releaseCamera() {
          if (camera != null) {
              camera.release();
              camera = null;
          }
      }
  }
  </code></pre>
  
  <p>Manifest, just in case:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.lexz.basiccamera"&gt;
  
      &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
      &lt;uses-permission android:name="android.permission.RECORD_AUDIO"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt; 
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>E/MediaRecorder: start failed: -19
  E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.lexz.basiccamera, PID: 28879
  java.lang.RuntimeException: start failed.
  at android.media.MediaRecorder.start(Native Method)
  at com.lexz.basiccamera.MainActivity$1.onClick(MainActivity.java:35)
  at android.view.View.performClick(View.java:4802)
  at android.view.View$PerformClick.run(View.java:20101)
  at android.os.Handler.handleCallback(Handler.java:810)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:189)
  at android.app.ActivityThread.main(ActivityThread.java:5529)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
  </code></pre>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Looks like for proper work camera class need to have SurfaceView, SurfaceHolder and implement SurfaceHolder.Callback and don't forget to set this surfaceview to camera. As working example <a href="https://stackoverflow.com/a/14952081/6134394">check this</a>.</p>