Skip to content Skip to sidebar Skip to footer

How To Mute/unmute Sound Of An Audio Using Javascript

I have created a fiddle of my function here( http://jsfiddle.net/rhy5K/10/ ) . Now i want to provide the Sound 'Mute/unpute' option for users. Example if i click on 'a link th

Solution 1:

Try

HTML5 Video_tag for display video with audio

or this below example along with html5 with jquery

window.my_mute = false;

$('#my_mute_button').bind('click', function(){

$('audio,video').each(function(){

    if (!my_mute ) {

        if( !$(this).paused ) {
            $(this).data('muted',true); //Store elements muted by the button.
            $(this).pause(); // or .muted=true to keep playing muted
        }

    } else {

        if( $(this).data('muted') ) {
            $(this).data('muted',false);
            $(this).play(); // or .muted=false
        }

    }
});

my_mute = !my_mute;

});

Solution 2:

I think you can use:

document.getElementById(id).volume = 1;

or

document.getElementById(id).volume = 0;

Post a Comment for "How To Mute/unmute Sound Of An Audio Using Javascript"