Last active
November 21, 2015 01:14
-
-
Save michaelgiles/0eb80a52303988e4b3e4 to your computer and use it in GitHub Desktop.
Youtube API Snippet
This file contains hidden or 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
// YOUTUBE API | |
var tag = document.createElement('script'); | |
tag.src = "http://www.youtube.com/player_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
var YT_Player; | |
var checkElem = setInterval(function(){ | |
if( $('#player') && $('#player')!=0 ){ | |
window.onYouTubePlayerAPIReady = function(){ | |
console.log('create the player'); | |
YT_Player = new YT.Player('player', { | |
height: '100%', | |
width: '100%', | |
videoId: '{{settings.video_id}}', | |
playerVars: { | |
modestbranding: 0, | |
rel: 0, | |
showinfo: 0, | |
autoplay: 0, | |
controls:0 | |
}, | |
events: { | |
'onReady': onPlayerReady, | |
'onStateChange': onPlayerStateChange | |
} | |
}); | |
clearInterval(checkElem); | |
} | |
} | |
}, 100); | |
function onPlayerReady(event){ | |
// console.log('player is ready'); | |
} | |
// State change event - STOP flexslider on video play | |
function onPlayerStateChange(event) { | |
if (event.data == YT.PlayerState.PLAYING) { | |
// console.log('video is playing'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment