AudioRecord未在Kindle Fire上初始化

时间:2014-07-09 14:31:10

标签: java android android-audiorecord

我正在使用以下方法来确定正确的AudioRecord初始化参数:

public AudioRecord findAudioRecord() {
    for (int rate : mSampleRates) {
        for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_PCM_8BIT }) {
            for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO }) {
                try {
                    Log.d("Mic", "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(AUDIO_SOURCE, rate, channelConfig, audioFormat, bufferSize);

                        if (recorder.getState() == AudioRecord.STATE_INITIALIZED)
                            return recorder;
                    }
                } catch (Exception e) {
                    Log.e("Mic", rate + "Exception, keep trying.",e);
                }
            }
        }
    }
    return null;
}

在我的代码中这样做:

recorder = findAudioRecord();
if(recorder != null)
   recorder.startRecording();
else 
   Log.e("Mic", "AudioRecord is null!");

它正在我测试的每个设备上工作(Galaxy S4,Droid Incredible,Razr),但是在Kindle Fire上AudioRecord为空。关于如何让它适用于Kindle Fire的任何建议?

谢谢!

0 个答案:

没有答案