Pir Fahim Shah
Pir Fahim Shah

Reputation: 10623

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();
}

Upvotes: 4

Views: 3719

Answers (2)

Jint
Jint

Reputation: 31

Giving Explicit Permission fixed the issue for me.

Try these steps

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

Upvotes: 2

disconnectionist
disconnectionist

Reputation: 508

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

Upvotes: 2

Related Questions