我正在尝试通过SoundPool
.
以下测试代码使第二次播放没有声音。仅当我在 HTC Hero 设备和模拟器上无限播放声音时才会出现这种情况。我正在使用安卓 1.6。
...
SoundPool soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
int soundId1 = soundPool.load(getApplicationContext(), R.raw.sound1, 1);
int soundId2 = soundPool.load(getApplicationContext(), R.raw.sound2, 1);
// the first one plays
int streamId = soundPool.play(soundId1, 1.0f, 1.0f, 1, -1, 1.0f);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
soundPool.stop(streamId);
// the second one doesn't play
streamId = soundPool.play(soundId2, 1.0f, 1.0f, 1, -1, 1.0f);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
soundPool.stop(streamId);
...