我创建了一个 MySoundPool 类(我将这个类用作 sigelton,但不认为这是相关的,因为其他一切都有效)。我正在初始化 SoundPool,一个 HashMap,并获取 AudioManager 的上下文。此后,我正在加载两个声音。MySoundpool 由方法 MySoundPool.playSound(int index, float rate) playSound 剪辑速率为 0.5 <= rate >= 2.0 并执行语句
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, index, 0, rate);
到现在为止还挺好。一切正常。不,在前一个声音仍在播放时调用 playSound ,我想在播放新声音之前停止它。在上面的代码片段之前我试过
mSoundPool.stop(mSoundPoolMap.get(index));
和
mSoundPool.autoPause();
没有成功。声音只是继续播放到最后。任何意见将不胜感激