Skip to content

Instantly share code, notes, and snippets.

@yankeyhotel
Created September 19, 2018 19:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yankeyhotel/e88c747dbc82a6685e34b28c7ebfc2d4 to your computer and use it in GitHub Desktop.
Save yankeyhotel/e88c747dbc82a6685e34b28c7ebfc2d4 to your computer and use it in GitHub Desktop.
youtube embed w/ mute and autoplay and loop
<iframe width="560" height="315" src="https://www.youtube.com/embed/ZHiVC_51KkI?rel=0&controls=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen=""></iframe>
<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: 'ZHiVC_51KkI', // 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();
},
onStateChange: function(e) {
if (e.data === YT.PlayerState.ENDED) {
player.playVideo();
}
}
}
});
}
// Written by @labnol
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment