目前我有四种方法可以将不同的声音加载到SoundPool中。我想通过一个带有参数并根据它加载不同文件的通用方法来简化/缩短我的代码。
目前,我有:
public void declareDrumsAmen(){
kick = currentDrums.load(myContext, R.raw.amenkick, 1);
hat = currentDrums.load(myContext, R.raw.amenhat, 1);
snare = currentDrums.load(myContext, R.raw.amensnare, 1);
snare2 = currentDrums.load(myContext, R.raw.amensnare2, 1);
}
public void declareDrumsFonk(){
kick = currentDrums.load(myContext, R.raw.fonkkick, 1);
hat = currentDrums.load(myContext, R.raw.fonkhat, 1);
snare = currentDrums.load(myContext, R.raw.fonksnare, 1);
snare2 = currentDrums.load(myContext, R.raw.fonksnare2, 1);
}
...
...
还有两个。我想用以下内容替换所有这些:
public void declareDrums(String kit){
kick = currentDrums.load(myContext, R.raw.kitkick, 1);
hat = currentDrums.load(myContext, R.raw.kithat, 1);
snare = currentDrums.load(myContext, R.raw.kitsnare, 1);
snare2 = currentDrums.load(myContext, R.raw.kitsnare2, 1);
}
但我不知道这样做。任何人都可以提供一些指导吗?
答案 0 :(得分:0)
方法定义:
public void declareDrums(int resIDkick, int resIDhat, int resIDsnare, int resIDsnare2){
kick = currentDrums.load(myContext, resIDkick, 1);
hat = currentDrums.load(myContext, resIDhat, 1);
snare = currentDrums.load(myContext, resIDsnare, 1);
snare2 = currentDrums.load(myContext, resIDsnare2, 1);
}
通话:
//declareDrums(R.raw.amenkick, R.raw.amenhat, R.raw.amensnare, R.raw.amensnare2);
declareDrums(R.raw.fpckick, R.raw.fpchat, R.raw.fpcsnare, R.raw.fpcsnare2);