2014-04-23 1 views
0

6 개의 버튼이 있으며 클릭 수에 따라 다른 .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

나는 당신과 같은 문제가있었습니다.

내 솔루션 :이

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

그것은에 작품을 좋아 한 OnCreate에서

이를 넣어 나를.

도와 드리겠습니다.

Regards, Piero.

관련 문제