How To Embed A YouTube Video With The Volume Muted

0
100

A huge majority of videos been watched on Facebook are muted. When you scroll through your Facebook timeline, be it from your smartphone app or the desktop app, the videos play automatically but the volume doesn’t come up unless you click and open the video. There is no harm in this though and it keeps you from disturbing other people around you as you watch the fourth cat video in your Facebook timeline. If you want to embed a YouTube video with the volume turned off by default, then you can use the script which was written by Amit Agarwal of Labnol that allows you to achieve that. The video will be played automatically but the sound will be muted. Any user that visits your website and wants to view the video will have to manually enable the volume. Here is how it works.

Visit YouTube and open the video you would want to embed and take note of the video’s ID from the Address or URL bar in your web browser. Take note of the string of text that follows just exactly after “https://www.youtube.com/watch?v=”

youtube video

Below is the script you need to embed in the video. You only need to replace the “YOUR_VIDEO_ID” in the eighth line with the video ID you just copied.

<div id="muteYouTubeVideoPlayer"></div>

<script async src="https://www.youtube.com/iframe_api"></script>
<script>
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('muteYouTubeVideoPlayer', {
videoId: 'YOUR_VIDEO_ID', // YouTube Video ID
width: 560, // Player width (in px)
height: 316, // Player height (in px)
playerVars: {
autoplay: 1, // Auto-play the video on load
controls: 1, // Show pause/play buttons in player
showinfo: 0, // Hide the video title
modestbranding: 1, // Hide the Youtube Logo
loop: 1, // Run the video in a loop
fs: 0, // Hide the full screen button
cc_load_policty: 0, // Hide closed captions
iv_load_policy: 3, // Hide the Video Annotations
autohide: 0 // Hide video controls when playing
},
events: {
onReady: function(e) {
e.target.mute();
}
}
});
}
// Written by @labnol
</script>

After embedding this code, the YouTube video will be muted. Below is the screenshot of how it will look.

youtube video

Please NOTE: this won’t work on videos that cannot be embedded i.e. videos that have restrictions on embedding but it will work on any other video.

Via Labnol

LEAVE A REPLY

Please enter your comment!
Please enter your name here