youtube iframe api get current time

Solutions on MaxInterview for youtube iframe api get current time by the best coders in the world

showing results for - "youtube iframe api get current time"
Beatrice
30 Nov 2016
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}