Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: startRecording() called on an uninitialized AudioRecord when SAMPLERATE set to 44100

I get an error, when I set the sampling rate to 44100 for the AudioRecord object. When it's 22050 it works fine.

02-16 10:45:45.099 24021-24021/com.vlad.jackcomms E/AudioRecord﹕ frameCount 1024 < minFrameCount 1792

02-16 10:45:45.099 24021-24021/com.vlad.jackcomms E/AudioRecord-JNI﹕ Error creating AudioRecord instance: initialization check failed.

02-16 10:45:45.099 24021-24021/com.vlad.jackcomms E/android.media.AudioRecord﹕ Error code -20 when initializing native AudioRecord object.

02-16 10:45:45.109 24021-24021/com.vlad.jackcomms E/AndroidRuntime﹕ FATAL

EXCEPTION: main Process: com.vlad.jackcomms, PID: 24021 java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

Here's the relevant code:

private static final int RECORDER_SAMPLERATE = 22050*2;
private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;

    recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
            RECORDER_SAMPLERATE, RECORDER_CHANNELS,
            RECORDER_AUDIO_ENCODING, BufferElements2Rec * BytesPerElement);

    recorder.startRecording();
like image 854
user3333414 Avatar asked Feb 16 '15 10:02

user3333414


1 Answers

Don't forget to ask for AUDIO_RECORD permission too

private void checkRecordPermission() {

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO},
                123);
    }
like image 180
Cédric Dufouil Avatar answered Oct 07 '22 01:10

Cédric Dufouil