I am trying to get AudioRecord instance but I get errors:
Could not get audio input for record source 1
Error creating AudioRecord instance: initialization check failed.
Error code -20 when initializing native AudioRecord object.
Here is my sample code:
public class AudioCapturer {
AudioRecord recorder;
private int channelConfig = AudioFormat.CHANNEL_IN_STEREO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
private static final int AUDIO_SAMPLE_RATE = 8000;
private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 };
int bufferSize = AudioRecord.getMinBufferSize(mSampleRates[3], channelConfig, audioFormat);
protected void Start() {
new Thread(new Runnable() {
public void run() {
recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, mSampleRates[3], channelConfig, audioFormat, bufferSize);
Log.v("RECORDER","" +recorder.getState());
recorder.startRecording();
while(recorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
{
byte [] buffer = new byte[bufferSize];
Log.v("READ RESULT","" + recorder.read(buffer, 0, buffer.length));
}
}
}).start();
}
}
I've added permissions but result is still the same.
My mobile phone API version is 18.