Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mute an html5 video player using jQuery

I've found how to pause and play the video using jquery

$("video").get(0).play(); $("video").get(0).pause(); 

But I can't find the mute button, if there isn't a jquery solution, I'm fine with just an onclick js solution. I need it asap.

Also is there a way to fix the mute delay? I want it to mute/unmute the sound as soon as the button is clicked.

like image 573
Cody Avatar asked Jun 16 '11 18:06

Cody


People also ask

How do I mute and unmute a video in JavaScript?

var button = document. getElementById('mute'); button. onclick = function (){ if (video. muted = false) { video.

How do I mute a JavaScript sound?

To mute all sound in a page with JavaScript, we can set the muted property of each audio element to true . to add the audio elements. We select all the audio and video elements with querySelectorAll . Then we loop through each element in elems and set the muted property of it to true to mute the audio.

How do you mute a website in JavaScript?

Hold a reference to all audio/video elements inside an array and then make a function which performs a loop over them while setting the . muted=true .


1 Answers

$("video").prop('muted', true); //mute 

AND

$("video").prop('muted', false); //unmute 

See all events here

(side note: use attr if in jQuery < 1.6)

like image 57
Naftali Avatar answered Oct 09 '22 07:10

Naftali