Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioFlinger could not create record track, status: -1 Error creating AudioRecord instance: initialization check failed with status -1

I am getting this error when i try to run the code at android 6.0 device

AudioFlinger could not create record track, status: -1 Error creating AudioRecord instance: initialization check failed with status -1.

I have this code which works well on lower version device

private void startRecording()
{
    bufferSize = AudioRecord.getMinBufferSize(11025,
        AudioFormat.CHANNEL_CONFIGURATION_MONO,
        AudioFormat.ENCODING_PCM_16BIT);

    recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
        11025, AudioFormat.CHANNEL_CONFIGURATION_MONO,
        RECORDER_AUDIO_ENCODING, 1024);

    int i = recorder.getState();

    if (i==1)
    {
        recorder.startRecording();
        ShowToast("Recording started successfully");
    }

    isRecording = true;

    recordingThread = new Thread(new Runnable()
    {
        @Override
        public void run() 
        {
            writeAudioDataToFile();
        }
    }, "AudioRecorder Thread");

    recordingThread.start();
}
like image 495
Pir Fahim Shah Avatar asked Oct 19 '25 07:10

Pir Fahim Shah


2 Answers

I assume you have already set the <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> permissions in manifest.xml

On Android versions > 6.0 audio is considered a "dangerous" permission, so you also need to ask permission at runtime by adding code. Instructions on that are here:

https://developer.android.com/training/permissions/requesting.html

like image 174
disconnectionist Avatar answered Oct 21 '25 20:10

disconnectionist


Giving Explicit Permission fixed the issue for me.

Try these steps

Android Version 7.0 Settings -> Applications -> -> Permissions -> [Turn Camera and Microphone ON]

like image 27
Jint Avatar answered Oct 21 '25 21:10

Jint