【发布时间】:2015-04-13 08:25:43
【问题描述】:
我在 soundpool.builder 中加载声音样本时遇到问题,同时在已弃用的 soundpool 中所有声音都可以正常工作。我的代码:
public void createNewSoundPool(Context context, int value){
AudioAttributes attributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
soundPool = new SoundPool.Builder()
.setAudioAttributes(attributes)
.setMaxStreams(10)
.build();
if(value==1) {
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
loaded= true;
}
});
soundIds[0] = soundPool.load(context, R.raw.one, 1);
soundIds[5] = soundPool.load(context, R.raw.stick, 6);
soundIds[3] = soundPool.load(context, R.raw.loss, 4);
soundIds[4] = soundPool.load(context, R.raw.win, 5);
}
if(loaded==true) {
if (value == 1) {
soundPool.play(soundIds[0], 1, 1, 1, 0, 1);
}
if(value==2){
soundPool.play(soundIds[1],1,1,1,0,1);
}else if(value==3){
soundPool.play(soundIds[2],1,1,1,0,1);
}else if(value==4){
soundPool.play(soundIds[3],1,1,1,0,1);
}else if(value==5){
soundPool.play(soundIds[4],1,1,1,0,1);
}else if(value==6){
soundPool.play(soundIds[5],1,1,1,0,1);
}else if(value==7){
soundPool.play(soundIds[6],1,1,1,0,1);
}else if(value==8){
soundPool.play(soundIds[7],1,1,1,0,1);
}
我有多个不同声音的级别,但一个级别中不超过 4 个声音。 使用 if else by there 值播放声音。
类似的代码适用于不推荐使用的声音池,它正在工作
【问题讨论】:
-
我检查并 log.i 显示所有 4 种声音都已加载但仍然没有声音。并在 logcat 中说该示例尚未准备好