c# - Why won't this sound stop playing? -


i have written little piece of code user can mute or unmute sounds in application.

private void volumebutton_click(object sender, routedeventargs e) {     if(muted==false)     {         muted = true;     }      if (muted == true)     {         muted = false;     } } 

i have written soundplayer method this:

public void playsound(string path) {     var p1 = new system.windows.media.mediaplayer();     if (muted == false)     {         p1.open(new uri(path, urikind.relative));         p1.play();     } } 

if click mute button application doesn't care, still plays sounds if nothing happened.

as described in comments (courtesy of bradleydotnet) issue within volumebutton_click method. both if statements being executed, meaning muted always false:

if (muted == false) {     muted = true; }  // muted equals true, regardless. if (muted == true) {     muted = false; } 

what want instead if /else if method:

if (muted == false) {     muted = true; } else if (muted == true) {     muted = false; } 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -

php - Mongodb connectivity error -