Created
May 13, 2014 14:38
-
-
Save egermano/d41ab15b03c3455870c4 to your computer and use it in GitHub Desktop.
YT Embed API events implements
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
var thePlayer = new YT.Player('yt-embed', { | |
height: '360', | |
width: '540', | |
videoId: 'bScJ8bbwMNM', | |
events: { | |
'onStateChange': function(e){ | |
switch (e.data) { | |
case YT.PlayerState.ENDED: | |
clearWatcherVideo(); | |
break; | |
case YT.PlayerState.PLAYING: | |
watcherVideo(); | |
break; | |
case YT.PlayerState.PAUSED: | |
clearWatcherVideo(); | |
break; | |
case YT.PlayerState.BUFFERING: | |
break; | |
case YT.PlayerState.CUED: | |
break; | |
} | |
} | |
}}) | |
function logVideoPercentual() { | |
var total = thePlayer.getDuration(), | |
current = thePlayer.getCurrentTime(); | |
console.log('percentual played', (current/total) * 100); | |
} | |
function watcherVideo () { | |
window.videoInterval = setInterval(function(){ | |
logVideoPercentual(); | |
}, 1000); | |
} | |
function clearWatcherVideo() { | |
clearInterval(window.videoInterval); | |
logVideoPercentual(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment