1var tag = document.createElement('script');
2tag.src = "https://www.youtube.com/iframe_api";
3var firstScriptTag = document.getElementsByTagName('script')[0];
4firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
5
6var player;
7function onYouTubeIframeAPIReady() {
8 player = new YT.Player('player', {
9 videoId: 'M7lc1UVf-VE',
10 events: {
11 'onStateChange': onPlayerStateChange
12 }
13 });
14}
15
16function onPlayerStateChange(event) {
17 console.log( player.playerInfo.currentTime );
18}