javascript - Mute button for my canvas animation -


i have sound playing in canvas animation @ specified time in animation sequence.

the code using is:

var snd = new audio("sounds/explosion.mp3"); snd.play(); 

the sound works perfectly. want include mute button mute sound on page @ 1 time, accessibility reasons.

i not sure how go appreciated.

an example using javascript audio object muted property both test mute state , set mute.

<button id="mute">mute</button>  <script>  var snd = new audio("sounds/explosion.mp3"); snd.play();  document.getelementbyid('mute').addeventlistener('click', function (evt) {   if ( snd.muted ) {     snd.muted = false     evt.target.innerhtml = 'mute'   }   else {     snd.muted = true     evt.target.innerhtml = 'unmute'   } }) </script> 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -