我已经像这样设置了 AudioTrack:
public NoiseThread(byte[] data)
{
rawData = data;
bufferSize = 2* AudioTrack.getMinBufferSize (44000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, bufferSize, AudioTrack.MODE_STREAM);
track.setStereoVolume(volume, volume);
}
public void run() {
setPriority(MAX_PRIORITY);
track.play();
while(!isInterrupted()){
track.write(rawData, 0, bufferSize);
}
track.stop();
}
正如我所期望的那样,样本通过扬声器播放。当我插入耳机时,扬声器关闭,但声音来自手机的听筒而不是耳机。如何通过耳机播放?