Question

I'm pereraing a youtube api player for my mp3 site, but i see these errors on console but everything is working properly!

Uncaught TypeError: Cannot read property 'getPlayerState' of undefined
Uncaught TypeError: undefined is not a function

How can I fix it these errors.

Was it helpful?

Solution

I had the same errors. I changed the stop() to fix them.

Normal function: StopVideo();

The "clean" code:

<a id="stop" href="#">Stop</a>

<iframe id="popup-youtube-player" width="640" height="360" src="http://www.youtube.com/embed/geTgZcHrXTc?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0" allowfullscreen="true" allowscriptaccess="always"></iframe>

$('#stop').on('click', function() {
    //$('#popup-youtube-player').stopVideo();
$('#popup-youtube-player')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');    
});

http://jsfiddle.net/3J2wT/266/

I hope it will be help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top