JavaScript Detect quando o vídeo do YouTube termina

/*you will need to use the youtube iframe api*/
/*https://developers.google.com/youtube/iframe_api_reference */
var player = new YT.Player("video_holder_id",{
            width: '640',
            height: '390',
            videoId: "eXvLdB4zwsY",
            events: {
                'onReady': function(event){
                    console.log("video is ready");
                    event.target.playVideo();
                },
                'onStateChange': function(event){
                     if (event.data == YT.PlayerState.ENDED) {
                       //video has ended
                    }   
                }
    }
});
Friendly Hawk