我已經解決了這個錯誤像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