Last active
August 29, 2015 14:18
-
-
Save jonathanhefner/5ebf7ef4ef57df5ea744 to your computer and use it in GitHub Desktop.
Fast Youtube playback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<!-- 1. The <iframe> (and video player) will replace this <div> tag. --> | |
<div id="player"></div> | |
<script type="text/javascript"> | |
var youtubeVideoId = window.location.hash ? window.location.hash.substring(1) : 'ylLzyHk54Z0'; | |
//var apiOrigin = 'http://jsbin.com'; | |
// 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', { | |
height: '390', | |
width: '640', | |
videoId: youtubeVideoId, | |
playerVars: { | |
html5: 1, | |
controls: 0, | |
modestbranding: 0, | |
showinfo: 0, | |
//origin: apiOrigin, | |
rel: 0 | |
}, | |
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