I am having problem with media recorder in android. I am recording an audio which works well with LG P500 but the same code is not working on Samsung GT - S5360. I am getting error as start failed -22.
This is the code I am using:
final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
try {
recorder.prepare();
recorder.start();
} catch (Exception e) { Log.d(TAG, "Exception : " + e); }
When debugging got cause as null in logcat.
Please suggest me some solution.
I had the same issue, and I tried installing a voice recorder from the play store to check. It didn't allow me to record VOICE_CALL too. From that I realised some device manufacturers don't support this. So record with the MIC if the device doesn't support VOICE_CALL.
The permission suggested by the op did not work for me, probably because it does not exist:)
If you are getting this error check the way you are setting up the media recorder. In my case it only failed in some devices as well. I was doing this for all devices running Os version > API 10:
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
Turns out that the faulting device was running JB but didn't support wideband, so changing it to raw/narrowband worked:
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Based on the comment of the actual poster... he suggested his answer in the comment. Putting this into an actual answer, hoping that it helps others:
The OP added the following permission and his code worked well for him:
<uses-permission android:name="android.permission.STORAGE" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.