I try to pause an iframe embedded YouTube video without a video-related event trigger.
I have read the youtube embedded api, this answer and this one and here is what I have so far (the video wont play in the snippet because of a CORS issue, but I guess it doesn't really matter.):
<iframe id="video1" width="560" height="315" src="http://www.youtube.com/embed/JFBUJ6kNl28" frameborder="0" allowfullscreen></iframe>
<script type="text/javascript">
//youtube api to pause video when changing section
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player = false
function onYouTubeIframeAPIReady() {
player = new YT.Player('video1', {});
}
function jump() {
console.log(player);
if (player) {
player.pauseVideo()
}
}
</script>
<button type="button" onclick="jump()" name="button">pause button</button>
What am I missing? The player object is there when I log it but it throws me a player.pauseVideo() is not a function