Android MediaRecorder - "start failed: -19"
android, android-camera, android-mediarecorder
Solution
Just found out the bug, in this line:
mediaRecorder.setVideoSize(sView.getWidth(), sView.getHeight());
after commenting out this line, the code runs perfectly!
Problem
I'm trying to create a video recorder on Android, and I've prepared my code which is supposed to be working - but I constantly get an error message `start failed: -19`. Here's my code: ``` public boolean startRecording() { try { camera.unlock(); mediaRecorder = new MediaRecorder(); mediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() { @Override public void onError(MediaRecorder mr, int what, int extra) { Log.i(TAG, "Error"); } }); mediaRecorder.setCamera(camera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); Log.i(TAG, "a"); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); Log.i(TAG, "b"); mediaRecorder.setMaxDuration(maxDurationInMs); // set to 20000 String uniqueOutFile = OUTPUT_FILE + System.currentTimeMillis() + ".3gp"; File outFile = new File(uniqueOutFile); if (outFile.exists()) { outFile.delete(); } mediaRecorder.setOutputFile(uniqueOutFile); mediaRecorder.setVideoFrameRate(videoFramesPerSecond); // set to 20 mediaRecorder.setVideoSize(sView.getWidth(), sView.getHeight()); Log.i(TAG, "c"); mediaRecorder.setPreviewDisplay(holder.getSurface()); mediaRecorder.setMaxFileSize(maxFileSizeInBytes); // set to 50000 mediaRecorder.prepare(); Log.i(TAG, "d"); mediaRecorder.start(); Log.i(TAG, "e"); return true; } catch (IllegalStateException e) { Log.i(TAG, "f"); Log.e(TAG, e.getMessage()); e.printStackTrace(); camera.lock(); return false; } catch (IOException e) { Log.i(TAG, "g"); Log.e(TAG, e.getMessage()); e.printStackTrace(); camera.lock(); return false; } catch (RuntimeException e) { Log.i(TAG, "h"); Log.e(TAG, e.getMessage()); camera.lock(); return false; } } ``` All the debug logs (from "a" through "d") are printed in log, so it seems that all the steps upto `mediaRecorder.prepare()` are properly done. Then it catches a `RuntimeException` with message `start failed: -19`. There is a similar question, but that doesn't solve my problem. Is there any other reason to get such an error?