我有不同的按钮,每个按钮都有自己的声音效果。 为了启用我的音效,我使用了这个类:
enter code here
public class Effects {
private static final String TAG = Effects.class.toString();
private static final Effects INSTANCE = new Effects();
public static final int SOUND_1 = 1;
public static final int SOUND_2 = 2;
private Effects() {
}
public static Effects getInstance() {
return INSTANCE;
}
private SoundPool soundPool;
private HashMap<Integer, Integer> soundPoolMap;
int priority = 1;
int no_loop = 0;
private int volume;
float normal_playback_rate = 1f;
private Context context;
public void init(Context context) {
this.context = context;
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(SOUND_1, soundPool.load(context, R.raw.laser, 1));
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
}
public void playSound(int soundId) {
Log.i(TAG, "!!!!!!!!!!!!!! playSound_1 !!!!!!!!!!");
soundPool.play(soundId, volume, volume, priority, no_loop, normal_playback_rate);
}
然后我以这种方式在我的活动中识别这个类:
Effects.getInstance().init(this);
然后当我点击我的按钮时,它的工作正常。
Effects.getInstance().playSound(Effects.SOUND_1);
现在我想要另一个按钮来禁用这些声音效果。 当我单击禁用按钮以禁用时:
button(my button's name).setSoundEffectsEnabled(false);
它根本不起作用。
问题是什么?