Android SoundPool没有';t工作-只需发出咔嗒声

Android SoundPool没有';t工作-只需发出咔嗒声,android,audio,soundpool,Android,Audio,Soundpool,我有六个按钮,想根据点击播放不同的.mp3文件。我实现了onClick方法,如下所示: SoundPool sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); if(view = screamButton) { soundId = sp.load(getContext(), R.raw.scream, 1); } // Some else if - statements sp.play(soundId, 5, 5, 0, 0,

我有六个按钮,想根据点击播放不同的.mp3文件。我实现了onClick方法,如下所示:

SoundPool sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);

if(view = screamButton) {
     soundId = sp.load(getContext(), R.raw.scream, 1);
}
// Some else if - statements

sp.play(soundId, 5, 5, 0, 0, 1);
我还尝试创建一个AudioManager来设置音量,但这并没有改变任何事情

有什么不对劲


汉克,我和你有同样的问题

我的解决办法是:

在OnCreate中,请将其放在以下位置:

    //The 20 is the maximum let the audio reproduce at the same time 
    sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    //volume control from the cellphone:
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    //load the audio
    soundId= sp.load(this,R.raw.scream,1);
     sp.play(soundId, 1, 1, 0, 0, 1);
最后,当你想要声音再现时,把这个:

    //The 20 is the maximum let the audio reproduce at the same time 
    sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    //volume control from the cellphone:
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    //load the audio
    soundId= sp.load(this,R.raw.scream,1);
     sp.play(soundId, 1, 1, 0, 0, 1);
对我来说没问题

我希望能帮助你

你好,皮耶罗