2014-04-23 44 views
0

我有六個按鈕,並希望根據點擊播放不同的.mp3文件。我已經實現了的onClick-方法是這樣的:Android SoundPool無法正常工作 - 僅發送點擊聲音

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設置音量,但這並沒有改變任何東西。

什麼可能是錯的?

漢克

回答

0

我有和你一樣的問題。

我的解決辦法是:

在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); 

它的工作原理確定我。

我希望能幫到你。

問候,皮耶羅。