Привет У меня возникла та же проблема при попытке инициализировать объект AudioRecord, и решение, которое я нашел, состояло в том, чтобы протестировать параметр конфигурации перед тем, как пытаться создать экземпляр текущего объекта AudioRecord. Вот процедура, которую я использовал:
/**
* Scan for the best configuration parameter for AudioRecord object on this device.
* Constants value are the audio source, the encoding and the number of channels.
* That means were are actually looking for the fitting sample rate and the minimum
* buffer size. Once both values have been determined, the corresponding program
* variable are initialized (audioSource, sampleRate, channelConfig, audioFormat)
* For each tested sample rate we request the minimum allowed buffer size. Testing the
* return value let us know if the configuration parameter are good to go on this
* device or not.
*
* This should be called in at start of the application in onCreate().
*
* */
public void initRecorderParameters(int[] sampleRates){
for (int i = 0; i < sampleRates.length; ++i){
try {
Log.i(TAG, "Indexing "+sampleRates[i]+"Hz Sample Rate");
int tmpBufferSize = AudioRecord.getMinBufferSize(sampleRates[i],
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
// Test the minimum allowed buffer size with this configuration on this device.
if(tmpBufferSize != AudioRecord.ERROR_BAD_VALUE){
// Seems like we have ourself the optimum AudioRecord parameter for this device.
AudioRecord tmpRecoder = new AudioRecord(MediaRecorder.AudioSource.MIC,
sampleRates[i],
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
tmpBufferSize);
// Test if an AudioRecord instance can be initialized with the given parameters.
if(tmpRecoder.getState() == AudioRecord.STATE_INITIALIZED){
String configResume = "initRecorderParameters(sRates) has found recorder settings supported by the device:"
+ "\nSource = MICROPHONE"
+ "\nsRate = "+sampleRates[i]+"Hz"
+ "\nChannel = MONO"
+ "\nEncoding = 16BIT";
Log.i(TAG, configResume);
//+++Release temporary recorder resources and leave.
tmpRecoder.release();
tmpRecoder = null;
return;
}
}else{
Log.w(TAG, "Incorrect buffer size. Continue sweeping Sampling Rate...");
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "The "+sampleRates[i]+"Hz Sampling Rate is not supported on this device");
}
}
}
Я надеюсь, что эта помощь.
Dickwan