Skip to content

Instantly share code, notes, and snippets.

@karla001
Last active June 27, 2022 05:16
Show Gist options
  • Save karla001/82e532afcb569d74895fea351f54a4d5 to your computer and use it in GitHub Desktop.
Save karla001/82e532afcb569d74895fea351f54a4d5 to your computer and use it in GitHub Desktop.
Used to mute and unmute an HTML <audio> tag when mute button was clicked.
function sound(){
$mutebutton.on('click',function(event) {
if($audio[0].muted === false){
$audio.attr('muted',true)
$audio[0].muted = true;
$mutebutton.text('Unmute');
console.log('Muted');
}else if($audio[0].muted === true){
$audio.removeAttr('muted')
$audio[0].muted = false;
$mutebutton.text('Mute');
console.log('Unmuted');
}
});
};
@karla001
Copy link
Author

This piece of code solved a problem dealing with a unique type of audio that was being captured by a hardware technology that was specific to said enterprise. The front end was able to take the information being given by the backend point and play only the latest audio file while also giving the user the ability to mute and unmute the audio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment