Question

I tried to record sound using audiorecorder method like below, it is fine on some devices but on the others it works just for first time when I want to use again it throws Error code -20 when initializing native AudioRecord object what is wrong?

final int RECORDER_BPP = 16;
int RECORDER_SAMPLERATE = 16000;
int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
int bufferSizeInBytes = AudioRecord
        .getMinBufferSize(RECORDER_SAMPLERATE, RECORDER_CHANNELS,
                RECORDER_AUDIO_ENCODING);
// Initialize Audio Recorder.
AudioRecord audioRecorder = new AudioRecord(
        MediaRecorder.AudioSource.MIC, RECORDER_SAMPLERATE,
        RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSizeInBytes);

audioRecorder.startRecording();
Was it helpful?

Solution

Just a guess but maybe you are not calling audioRecorder.release() after your done all the time. If so then it may work the first time but after that you might be holding on to audio resources unnecessarily and it might not work until you restart phone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top