I am trying to record video in my app, on my Nexus 5 and a ZTE this code works fine but on Samsumg Galaxy S2 and S3 fails with the exception "start failed -19" I'm a noob with the MediaRecorder, I only need a configuration that works on all cameras that record a .mp4 videofile file with normal quality.
try {
prCamera.unlock();
prMediaRecorder.setCamera(prCamera);
prMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
prMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
prMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoSize(720, 480);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoEncodingBitRate(3000000);
prMediaRecorder.setAudioEncodingBitRate(12200);
prMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
prMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
prMediaRecorder.setMaxDuration(cMaxRecordDurationInMs);
// Nombre del video de salida
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
nombreVideo = "video_" + timeStamp;
prRecordedFile = new File(cVideoFilePath + nombreVideo + ".mp4");
prMediaRecorder.setOutputFile(prRecordedFile.getPath());
prMediaRecorder.setPreviewDisplay(prSurfaceHolder.getSurface());
try {
prMediaRecorder.prepare();
// Fail on next line
prMediaRecorder.start();
} catch (IllegalStateException e) {
Log.d(tag, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (IOException e) {
Log.d(tag, "IOException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (Exception e) {
Log.d(tag, "Unknown exception preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
}
prRecordInProcess = true;
Why you don't use
I wasn't able to find the exact settings of this profile but I'm pretty sure the outputformat was mpeg4 and that is what you want... I remember that most media recorder problems regard to wrong setted parameters. Try use this profile. It guarantees the highest available and working setup for the device. You can read further informations about this and other profiles which may fits your needs better here http://developer.android.com/reference/android/media/CamcorderProfile.html#QUALITY_HIGH