I am creating a casual game. And I applied sounds when the button is clicked etc.. now I have an image button of speaker icon. I Want to disable the sounds when It is pressed. how do I do that?
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 */
});
}