开发者

SoundPool Not Loading in Android App

I'm making an app where I'm trying to load a single sound onto a SoundPool so I can manage the playback rate when I want, play it when I want, and release it when I want. However, my SoundPool is not loading. I've tried to change a lot of different things and nothing seems to work. I put a Log.d in the OnLoadComplete function to see if it loads, and the log doesn't appear when running... Maybe after looking at my code somebody else could help me. Thanks!

private int currentVoice = 0;
private SoundPool voices = null;
....
public void onCreate(Bundle savedInstanceState) {
....
    voices = new SoundPool(1, 3, 0);
    voices.setOnLoadCompleteListener(this);
....
}
private void giveSentence() throws IOException {
....
voices.release();
currentVoice = voices.load(this, sentences[index].voice, 1);
voices.play(currentVoice, 1, 1, 1, 0, 1f);

public void onLoadComplete(SoundPool soundPool, in开发者_开发知识库t sampleId, int status) {
    soundPool.play(sampleId, 1, 1, 1, 0, 1f);
    boolean loaded = true;
    Log.d("Game","Is it loaded? " + loaded);
}


You should initialize your sound pool somewhere in a onCreate method, I guess.

 private SoundPool voices;

 @Override
 public void onCreate(Bundle savedInstanceState) {
    voices = new SoundPool(1, 3, 0);
    voices.setOnLoadCompleteListener(this);
 }


Fixed myself, I was doing voices.release(); before anything was loaded. For some reason that just turned the SoundPool off. Took out that line and did voices.release() after I checked if it was already loaded. Now it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜