我正在尝试制作一个音频应用程序,它允许通过麦克风通过扬声器投射声音。我为这个应用程序做了一个切换按钮,但点击它后,它保持突出显示,我无法调整系统音量。那么我该如何打破这个循环呢?
私人无效setUpButton(){
final ToggleButton tb = (ToggleButton) findViewById(R.id.tb);
tb.setOnClickListener(new View.OnClickListener (){
public void onClick(View view) {
// TODO Auto-generated method stub
boolean on = ((ToggleButton) view).isChecked();
if (on){
boolean is = true;
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
int buffersize = AudioRecord.getMinBufferSize(20000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
AudioRecord arec = new AudioRecord(MediaRecorder.AudioSource.MIC, 20000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
AudioTrack atrack = new AudioTrack(AudioManager.STREAM_MUSIC, 20000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize, AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(20000);
byte[] buffer = new byte[buffersize];
arec.startRecording();
atrack.play();
while(is) {
arec.read(buffer, 0, buffersize);
atrack.write(buffer, 0, buffer.length);
}
}
}});
}