Any way to mute the sound yet keep it running in the background instead of stopping it completely?

StackOverflow https://stackoverflow.com/questions/21296390

  •  01-10-2022
  •  | 
  •  

Question

What the title says really, Right now I only know how to control the sound by using .Play and .Stop, however is there a way to mute the sound but still have it playing in the background?

Here is a snippet of the code:

    private void muteButton_Click(object sender, EventArgs e)
    {
        if (muteButton.Text == "Mute")
        {

            muteButton.Text = "Unmute";
            _soundPlayer.Stop();
        }

        else
        {
            muteButton.Text = "Mute";
            _soundPlayer.PlayLooping();
        }
        }
Was it helpful?

Solution

You should try this

private boolean playing = true;
private void muteButton_Click(object sender, EventArgs e)
{
    if (_soundPlayer.IsLoadCompleted)
    {
        if (playing)
           {
            _soundPlayer.Stop();
            playing = false;
            }
        else
            {
            _soundPlayer.Play();
             playing = true;
            }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top