Reputation:
I'm looking to create a mute button for a video on my page. My page has a background video with a loop and nothing else. But the sound is just very annoying after a while. I found a button to stop the video, but I can't play it again after. Also, I'm looking for a mute only button.
So that's my HTML currently.
<video autoplay id="bgvid" loop>
<source src="videos/chat/chat_noir.mp4" type="video/mp4">
</video>
<div class="mute" onclick="document.getElementById('bgvid').pause()">
<a href="#">Activer/Désaciver le son</a>
</div>
I have the .pause function, but how to make the video continue and only remove the sound? How to replay video or put the sound again?
Upvotes: 1
Views: 4077
Reputation: 6457
You just need to introduce the usage of muted
attribute of video
html tag as follows:
<div class="mute" onclick="document.getElementById('bgvid').muted = !document.getElementById('bgvid').muted">
<a href="#">Mute / Avtivate</a>
</div>
See working JSFiddle example.
Upvotes: 2