Skip to content

Instantly share code, notes, and snippets.

@jlyon
Last active September 2, 2017 22:44
Show Gist options
  • Select an option

  • Save jlyon/84da510b6745a64c446f8baa21b4f3f2 to your computer and use it in GitHub Desktop.

Select an option

Save jlyon/84da510b6745a64c446f8baa21b4f3f2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body style="background:#333;text-align:center;">
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player" style="width: 1170px;height: 585px;margin:20px auto;"></div>
<script>// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: window.location.hash.replace('#',''),
events: {
'onReady': onPlayerReady
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
//player.setPlaybackRate(2);
event.target.playVideo();
}</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment