问题描述
我希望能够加载大约30种声音中的5种,这取决于微调器的选择。我创建了initializeSoundPoolBank1-5()并将它们添加到onItemSelectedListener中的switch语句中。这不会播放声音,但是如果我直接从onCreate()调用initializeSoundPoolBank#,它将可以正常工作。我对编程和Android还是很陌生,意识到我必须缺少一些东西,但是似乎找不到关于此的任何特定文档。该应用程序不会崩溃,它只是什么都不会播放。任何帮助将不胜感激。这是我的代码。
<number>-<description>.rules
selectSoundBank.setonItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView,View view,int i,long l) {
int instrumentDirInt = selectSoundBank.getSelectedItemPosition();
switch (instrumentDirInt + 1){
case 1:
initializeSoundPoolBank1();
break;
case 2:
initializeSoundPoolBank2();
break;
case 3:
initializeSoundPoolBank3();
break;
case 4:
initializeSoundPoolBank4();
break;
case 5:
initializeSoundPoolBank5();
break;
default:
break;
}
}
@Override
public void onnothingSelected(AdapterView<?> adapterView) {
}
});
然后单击按钮播放。
public void initializeSoundPoolBank1(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
soundPool = new SoundPool.Builder()
.setMaxStreams(1)
.setAudioAttributes(audioAttributes)
.build();
}else {
soundPool = new SoundPool(16,AudioManager.STREAM_MUSIC,0);
}
soundPool.setonLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool,int sampleId,int status) {
loaded = true;
}
});
dum = soundPool.load(this,R.raw.darbdum,1);
ka = soundPool.load(this,R.raw.darbka,1);
cut = soundPool.load(this,R.raw.darbcut,1);
puk = soundPool.load(this,R.raw.darbpuk,1);
tek = soundPool.load(this,R.raw.darbtek,1);
Toast.makeText(this,"loaded",Toast.LENGTH_SHORT).show();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)