Using YouTube’s JavaScript API to control an iFrame embed. I’ve set up the functions and don’t see any errors… but I’m not logging the API’s initialization as documented here.
Yes, it’s running off a server, not locally: http://jp.redwoodmatthews.com
Am I missing something? HTML and JavaScript below! Thanks for your help.
iFrame HTML:
<iframe id="ryanBingham" src="http://www.youtube.com/v/Xz5SNppHRxc?rel=0?enablejsapi=1&version=3&playerapiid=video" frameborder="0"></iframe>
JavaScript:
function onYouTubePlayerReady(playerId) {
video = document.getElementById('ryanBingham');
video.addEventListener('onStateChange', 'onytplayerStateChange');
console.log('YouTube API initiated');
}
You’re on the wrong API docs. This is for iframes: https://developers.google.com/youtube/iframe_api_reference
Due to same origin restrictions, it works a bit differently. Also, the ready function is named
onYouTubeIframeAPIReady.Last but not least, make sure you load the API JS file