相关文章推荐
长情的楼房  ·  Chart 接口 ...·  8 月前    · 
乐观的滑板  ·  Mac OS ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.