我有个问题。当我尝试使用 Soundpool 播放声音时,每次播放之间会有短暂的停顿。例如,我有 2 秒的声音,我想在按下按钮时播放。我试图以相同的声音启动 2 个线程。第二次在第一次之后 0.5 秒开始。但没有任何帮助。
AudioManager mAudioManager;
SoundPool mSoundPool;
Runnable thr1;
Runnable thr2;
public void playLoopedSound(int soundId) {
mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)*2;
thr1 = new Runnable() {
public void run() {
mSoundPool.play(soundId, 0, streamVolume, 1, -1, 1f); //0 = no loop, -1 = loop forever
}
};
thr2 = new Runnable() {
public void run() {
mSoundPool.play(soundId, 0, streamVolume, 1, -1, 1f);
}
};
thr1.run();
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
thr2.run();
}