i want to record a video (with audio) from this app
but as soon as i press start recording it gives "E/MediaRecorder: start failed: -19"
i referred to this link ---> Android MediaRecorder - "start failed: -19" and according to them i set the supported videoSize but again i failed
and i have set the method calls according to the state diagram given on ---> "developer.android.com/reference/android/media/MediaRecorder.html" website
and i have set audio and video parameters as given on ---> "developer.android.com/guide/appendix/media-formats.html" website
but nothing seems to work :(
i am testing this on my phone Mi Redmi 2 running MIUI
this is how UI looks like ---> Cam UI
this is my code below:-
/*to Start recording*/
public void startRecording() {
Log.e(tag, "Begin StartRecording");
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
}
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setAudioChannels(1);
mRecorder.setAudioSamplingRate(24);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mRecorder.setAudioEncodingBitRate(24);
mRecorder.setVideoEncodingBitRate(56);
final List<Camera.Size> mSupportedVideoSizes = getSupportedVideoSizes(camera);
for (Camera.Size str : mSupportedVideoSizes)
Log.e(tag, "mSupportedVideoSizes "+str.width + ":" + str.height + " ... "
+ ((float) str.width / str.height));
File dir = Environment.getExternalStorageDirectory();
try {
audiofile = File.createTempFile("sound", ".mp4", dir);
} catch (IOException e) {
Log.e(tag, "external storage access error");
return;
}
mRecorder.setOutputFile(audiofile.getAbsolutePath());
mRecorder.setVideoSize(176, 144);
mRecorder.setVideoFrameRate(12);
mRecorder.setMaxDuration(20000);
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
try {
mRecorder.prepare();
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
Log.w(tag, e);
}
try {
mRecorder.start();
Toast.makeText(this, "Recording....", Toast.LENGTH_SHORT).show();
} catch (Throwable t) {
t.printStackTrace();
Log.w(tag, t);
}
}
/*To stop recording*/
public void stopRecording() {
Log.e("", "Begin StopChange");
if (mRecorder != null)
try {
mRecorder.stop();
Toast.makeText(this, "Recording STOPPED .. ", Toast.LENGTH_SHORT).show();
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
mRecorder.reset();
mRecorder.release();
mRecorder = null;
}
}
here is the Android Manifest permissions :---
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.STORAGE" />
Logcat :--->
E/MediaRecorder: start failed: -19
02-24 13:40:32.070 14892-14892/pkg.android.chintan.khetiya.cp W/System.err: java.lang.RuntimeException: start failed.
02-24 13:40:32.070 14892-14892/pkg.android.chintan.khetiya.cp W/System.err: at android.media.MediaRecorder.start(Native Method)
02-24 13:40:32.070 14892-14892/pkg.android.chintan.khetiya.cp W/System.err:
02-25 16:40:28.952 10315-10315/pkg.android.chintan.khetiya.cp I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
first i press the 1) start preview button then 2) start recording button then after making vid 3) stop recording finally 4) stop preview
please please tell me where am i wrong ... any help will be appreciated thanks in advance !