var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function stopVideo(id_iframe) {
document.getElementById('vid_'+id_iframe).contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*')
}
function init_video(video_id){
if (player) {
player.destroy();
}
console.log('init start!');
if(document.getElementById('vid_'+video_id).contentWindow){
document.getElementById('vid_'+video_id).contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
console.log('postMessage!');
}
var player;
player = new YT.Player('vid_'+video_id, {
height: '700',
videoId: video_id,
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady': onPlayerReady,
}
});
if(player){
console.log(player);
}
function onPlayerReady(event) {
console.log('onPlayerReady');
event.target.playVideo();
}
}