gpt4 book ai didi

android - Android Soundpool问题

转载 作者:行者123 更新时间:2023-12-03 02:12:57 24 4
gpt4 key购买 nike

最近,我一直在从事Android游戏,但是在添加音乐和其他声音时遇到了问题。我读到Mediaplayers是背景音乐的最佳选择,效果很好,并且我读到Soundpool对于诸如音效之类的短音乐片段是最佳的。但是,我无法使Soundpool正常工作,似乎Soundpool甚至没有加载。

我进行了更多研究,发现很多关于Soundpool缺乏支持的噩梦,所以我应该只使用Mediaplayer播放所有音频吗?这样有效吗?

//My Code
soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
loaded = true;
}
});

if(loaded==true){
soundId = soundPool.load(this, R.raw.sound1, 1);
soundPool.play(soundId, 1, 1, 1, 0, 1f);}
else{
System.exit(0);
}
//Forces the program to exit everytime

最佳答案

soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int mySoundId, int status) {
loaded = true;
soundId = soundPool.load(this, R.raw.sound1, 1);
soundPool.play(soundId, 1, 1, 1, 0, 1f);
}
});

因为您加载的变量将始终为false,所以您应该在onLoadComplete中执行操作。

关于android - Android Soundpool问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22572879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com