我尝试使用如下录音机方法录制声音,在 HTC nexus one android 2.3 中很好,但是当我在 LG 和 Sony 上使用 Android 4.0 和 4.1 尝试它时,它可以工作一次,下次尝试时它会在 startRecording 中抛出异常有java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
什么问题?
final int RECORDER_BPP = 16;
int RECORDER_SAMPLERATE = 16000;
int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
int bufferSizeInBytes = AudioRecord
.getMinBufferSize(RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING);
// Initialize Audio Recorder.
AudioRecord audioRecorder = new AudioRecord(
MediaRecorder.AudioSource.MIC, RECORDER_SAMPLERATE,
RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSizeInBytes);
audioRecorder.startRecording();