Why AudioRecord is not recording sound when device fall asleep even when I use WakeLock?

前端 未结 2 1114
攒了一身酷
攒了一身酷 2020-12-12 03:24

I\'m recording the sound from device with AudioRecord and write it to .wav file and I need it to keep recording and writing in file even wh

2条回答
  •  天涯浪人
    2020-12-12 03:43

    You should start recording/initialize AudioRecord in independent thread, and start this thread you need from foreground Service. Also right before start of recording change thread priority like in example below:

    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
    
    AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC,
                sampleRate,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                bufferSize);
    record.startRecording();
    

提交回复
热议问题