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

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -