Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're deferring the definition of <code>onYouTubePlayerAPIReady</code>. For this reason, it's likely that the YouTube API finishes before <code>onYouTubePlayerAPIReady</code> is defined. In that case, your code will fail.</p> <p>To solve the problem, check whether the API is ready at run-time.</p> <pre><code>window.onYouTubePlayerAPIReady = function () { player = new YT.Player('player', { height: '315', width: '560', videoId: 'bpOR_HuHRNs', }); }; if (window.YT) { // Apparently, the API was ready before this script was executed. // Manually invoke the function onYouTubePlayerAPIReady(); } </code></pre> <p>Note. For simple one-way functions, such as <code>player.playVideo()</code> and <code>player.pauseVideo()</code>, I recommend to use this simple function, which is not as bloated as the documented YouTube API. See <a href="https://stackoverflow.com/a/7513356/938089?youtube-iframe-api-how-do-i-control-a-iframe-player-thats-already-in-the-html">this answer</a>.</p> <p>Here's a the updated part of your page, using the <code>callPlayer</code> function from my other answer instead of the YouTube API: <a href="http://jsfiddle.net/ryyCZ/" rel="nofollow noreferrer">http://jsfiddle.net/ryyCZ/</a></p> <pre><code>&lt;div id="player"&gt; &lt;iframe width="560" height="315" frameborder="0" src="http://www.youtube.com/embed/bpOR_HuHRNs?enablejsapi=1"&gt;&lt;/iframe&gt; &lt;/div&gt; if ($(".slides_control &gt; div:visible #player").length == 1) { callPlayer("player","playVideo"); } else { callPlayer("player", "pauseVideo"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload