Search code examples
androidaudioradio-buttonmute

sound on/off in an app using radio button


I am working on a game, and want to switch sound to on and off using radio button. The sounds are running in my app in other options. when sound off radio button is pressed it should mute the sound until and unless sound on pressed. Can anyone help me out to solve this issue?

Thanks in advance


Solution

  • Try

    AudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    

    ..this should mute the default music stream. Pass in false to enable it again.