我已经解决了这个错误像this.becuse我们可以像这样调用AudioRecors对象。
private AudioRecord findAudioRecord() {
// TODO Auto-generated method stub
for (int rate : mSampleRates) {
for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT }) {
for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO }) {
try {
Log.d("AudiopRecording", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "
+ channelConfig);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
// check if we can instantiate and have a success
AudioRecord recorder = new AudioRecord(AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);
if (recorder.getState() == AudioRecord.STATE_INITIALIZED)
return recorder;
}
} catch (Exception e) {
Log.e("AudiopRecording", rate + "Exception, keep trying.",e);
}
}
}
}
return null;
}
http://stackoverflow.com/questions/4843739/audiorecord-object-not-initializing – 2013-03-11 09:25:14
谢谢,但我不能评论@Dustin在这个主题的解决方案。我试过这个解决方案,现在我得到错误getMinBuferSize()无效的音频格式 – user2043332 2013-03-11 11:09:19
你不能使用8位getMinBufferSize()最后我检查。使用16位而不是 – alrikai 2013-10-11 23:16:18