简体   繁体   中英

How do I mute and unmute my sound playing in the the button

i am planning to make a sound button and for the button I have two images one for ENABLE and one for DISABLE state for sound. i want to enable and disable the sound of different buttons through these buttons.

Create just one Button and add something like a buttonstatus. Then you can check the status in your listener. For example:

boolean isPlaying = false;
playPause = (Button) findViewById(R.id.play);
playPause.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
     if (isPlaying) {
       pause();
     }else{
       play();
     }
       isPlaying = !isPlaying;
     }
     });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM