问题
hello I have this code
AudioTrack audioTrack;
public void playAccordeon() {
int minBufferSize = AudioTrack.getMinBufferSize(44100,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
int bufferSize = 512;
if (audioTrack == null) {
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBufferSize,
AudioTrack.MODE_STREAM);
audioTrack.play();
}
int i = 0;
byte[] s = new byte[bufferSize];
try {
InputStream fin = getResources().openRawResource(R.raw.accordeon);
while ((i = fin.read(s)) != -1) {
audioTrack.write(s, 0, i);
}
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
its works but there is one problem, when I play sound first time it plays fine, but second and third.. play have sound like "click" (I tried many sound files)
what to do? thanks
来源:https://stackoverflow.com/questions/11203474/android-play-sound-with-audiotrack