Skip to content

Instantly share code, notes, and snippets.

@vitalbone
Created September 16, 2019 11:09
Show Gist options
  • Save vitalbone/035d173113f993f99259a93fac98a617 to your computer and use it in GitHub Desktop.
Save vitalbone/035d173113f993f99259a93fac98a617 to your computer and use it in GitHub Desktop.
Auto play video
<% include partials/header%>
<div class="container-fluid">
<div class="row">
<%videos.forEach((video) => {%>
<div class="col-lg-4">
<div class="card m-1">
<div class="card-body">
<p>
<h5><%=video.title%></h5>
</p>
<iframe width="1000" height="900" class="img-thumbnail"
src="https://www.youtube-nocookie.com/embed/<%=video.url%>?enablejsapi=1&version=3&playerapiid=ytplayer"
frameborder="0" allow="accelerometer; autoplay;
encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
</div>
<%})%>
</div>
<script>
setTimeout(() => {
const vids = document.getElementsByClassName('img-thumbnail');
vids[0].contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*')
}, 2000);
</script>
</div>
<% include partials/footer%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment