当我尝试使用以下代码通过我的Nexus 5录制音频时
record = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_8BIT,BYTE_OF_SAMPLE * bufferSampleSize); record.startRecording();
然后我在logcat中得到以下异常:
E/AudioRecord: AudioFlinger could not create record track,status: -1 E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check Failed with status -1. E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object. E/AndroidRuntime: FATAL EXCEPTION: Thread-855 E/AndroidRuntime: Process: com.*.*,PID: 14206 E/AndroidRuntime: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord. E/AndroidRuntime: at android.media.AudioRecord.startRecording(AudioRecord.java:885) E/AndroidRuntime: at com.*.*.MainActivity$Looper.run(MainActivity.java:265) E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9e476d00
<uses-permission android:name="android.permission.RECORD_AUdio" />
我已经测试了AudioRecord object not initializing.这些解决方案都没有.
但它在另一个项目中工作.
有什么遗漏?