我正在尝试从麦克风录制声音然后播放,但我这里只有咔哒声。AudioTrack 和 AudioRecord 的设置相同,并且初始化正确。这是我的代码:
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isRecording = false;
recordingThread.join();
player = findAudioTrack();
player.play();
for (int i = 0; i < audioQueue.size(); i++) {
int written = player.write(audioQueue.get(i), 0,
audioQueue.get(i).length);
}
player.stop();
player.release();
player = null;
}
});
}
private void startRecording() {
recorder = findAudioRecord();
recorder.startRecording();
isRecording = true;
recordingThread = new Thread(new Runnable() {
public void run() {
addAudioToQueue();
}
}, "AudioRecorder Thread");
recordingThread.start();
}
private void addAudioToQueue() {
short[] capturedAudio = new short[recordBufferSize/2];
while (isRecording) {
int read = recorder.read(capturedAudio, 0, capturedAudio.length);
audioQueue.add(capturedAudio);
}
recorder.stop();
recorder.release();
recorder = null;
}
}
有人知道为什么吗?
这是完整的源代码: https ://www.dropbox.com/s/h38cs9vjkztyyro/AudioTesting.java