Java – audiorecord object is not initialized in the project

When I try to record audio with my nexus 5 using the following code

record = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_8BIT,BYTE_OF_SAMPLE * bufferSampleSize);
record.startRecording();

Then I get the following exception in 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

I added the following line to the manifest file

<uses-permission android:name="android.permission.RECORD_AUdio" />

I have tested audiorecord object not initializing None of these solutions exist

But it works on another project What's missing?

Solution

Got the solution:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>