【发布时间】:2018-02-24 21:52:36
【问题描述】:
我正在制作一款休闲游戏。我在单击按钮时应用了声音等。现在我有一个扬声器图标的图像按钮。我想在按下它时禁用声音。我怎么做?
I used sound pool here is my sound loop class:
public class SoundPool {
private static SoundPool soundpool;
private static int clicksound;
private static int gameosound;
private static int scoreupsound;
public SoundPlayer (Context context) {
soundpool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
clicksound = soundpool.load(context,R.raw.click, 1);
gameosound= soundpool.load(context,R.raw.gameover, 1);
scoreupsound = soundpool.load(context,R.raw.score, 1);
}
public void playclicksound() {
soundpool.play(clicksound, 1.0f, 1.0f, 1, 0, 1.0f);
}
public void playgameosound() {
soundpool.play(gameosound, 1.0f, 1.0f, 1, 0, 1.0f);
}
public void playscoreupsound() {
soundpool.play(scoreupsound, 1.0f, 1.0f, 1, 0, 1.0f);
}
}
public class MainActivity {
private TextView word1;
private ImageButton speakericon;/* I want to change image when pressed*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
word1 = (TextView) findViewById(R.id.word1);
word1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sound.playclicksound(); /* I want to cancel this sound when the speaker icon is pressed */
});
}
【问题讨论】: