我正在尝试使用AudioRecord类录制一些音频。这是我的代码:
int audioSource = AudioSource.MIC;
int sampleRateInHz = 44100;
int channelConfig = AudioFormat.CHANNEL_IN_MONO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int bufferSizeInShorts = 44100;
int bufferSizeInBytes = 2*bufferSizeInShorts;
short Data[] = new short[bufferSizeInShorts];
Thread recordingThread;
AudioRecord audioRecorder = new AudioRecord(audioSource,
sampleRateInHz,
channelConfig,
audioFormat,
bufferSizeInBytes);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void startRecording(View arg0) {
audioRecorder.startRecording();
recordingThread = new Thread(new Runnable() {
public void run() {
while (Data[bufferSizeInShorts-1] == 0)
audioRecorder.read(Data, 0, bufferSizeInShorts);
}
});
audioRecorder.stop();
}
不幸的是,录制结束后我的短阵列是空的。我可以请你帮我弄清楚出了什么问题吗?