Skip to content

Instantly share code, notes, and snippets.

@Usse
Last active December 17, 2015 19:38
Show Gist options
  • Save Usse/5661393 to your computer and use it in GitHub Desktop.
Save Usse/5661393 to your computer and use it in GitHub Desktop.
Youtube api boilerplate
<div style="width:759px; height:427px;" id="ytPlayer"></div>
var video = {
player : null,
init : function() {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var done = false;
$("#goBackstage").on("click", function() {
video.player.stopVideo();
})
}
}
function onYouTubeIframeAPIReady() {
video.player = new YT.Player('ytPlayer', {
height: '427',
width: '759',
videoId: 'VIDEO_ID',
playerVars: {
'controls': 0,
'rel' : '0',
'modestbranding' : 0,
'showinfo' :0
}
});
}
function stopVideo() {
video.player.stopVideo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment