I have done it. The only issue is clicking on the video does take the user to Youtube. The video will be on top by default, and will load a millisecond faster. If you want it to be behind a transparent published Animate object, use z-index.
Just create a player div and position it where you want it to appear.
<div id="player"></div>
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '184',
width: '300',
videoId: '**********',
playerVars: {
'autoplay': 1,
'modestbranding':1,
'controls': 1,
'fs': 0,
'rel': 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
var playerReady = false;
function onPlayerReady(event) {
playerReady = true;
player.mute();
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
<!-- alert('done'); -->
}
}