本文介绍了AudioRecord对象未在项目中初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用以下代码通过我的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无法创建记录轨道,状态:-1 
E / AudioRecord-JNI:创建AudioRecord实例时出错:初始化检查失败,状态为-1。
E / android.media.AudioRecord:初始化本机AudioRecord对象时的错误代码-20。
E / AndroidRuntime:FATAL EXCEPTION:Thread-855
E / AndroidRuntime:Process:com。*。*,PID:14206
E / AndroidRuntime:java.lang.IllegalStateException:startRecording()呼吁未初始化的AudioRecord。
E / AndroidRuntime:在android.media.AudioRecord.startRecording(AudioRecord.java:885)
E / AndroidRuntime:at com。*。*。MainActivity $ Looper.run(MainActivity.java:265)
E / Surface:getSlotFromBufferLocked:未知缓冲区:0x9e476d00

我添加了以下行清单文件。

 < uses-permission android:name =android.permission.RECORD_AUDIO/> 

我已经测试了


When I am trying to record an audio through my Nexus 5 using 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 am getting following exceptions 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've added following line in manifest file.

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

I've tested AudioRecord object not initializing. None of those solutions working.

But its working in another project.Is there anything missing?

解决方案

Got the solution:Recently I updated my phone to Marshmallow. In Marshmallow there is a new permission system. I switched on these permissions as bellow the recording works just fine.

这篇关于AudioRecord对象未在项目中初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:46