Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A working example of the below code is also on <a href="http://jsfiddle.net/vPELX/2/">jsfiddle.net</a>.</p> <p>Some notes:</p> <ul> <li>Uses the <a href="https://developers.google.com/youtube/iframe_api_reference">iframe_api</a>, not the <a href="https://developers.google.com/youtube/js_api_reference">javascript_api</a></li> <li>The YT.Player constructor is minimal because you are building the iframe yourself.</li> <li>The "playerVars" are included as iframe URL parameters.</li> <li>The parameter "enablejsapi=1" is set.</li> </ul> <h3>Example Markup</h3> <pre><code>&lt;script src="http://www.youtube.com/iframe_api"&gt;&lt;/script&gt; &lt;a style="display: block;" class="video-thumb" id="HuGbuEv_3AU" href="#"&gt; Megadeth: Back In The Day &lt;/a&gt; &lt;a style="display: block;" class="video-thumb" id="jac80JB04NQ" href="#"&gt; Judas Priest: Metal Gods &lt;/a&gt; &lt;a style="display: block;" class="video-thumb" id="_r0n9Dv6XnY" href="#"&gt; Baltimora: Tarzan Boy &lt;/a&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;div id="log"&gt;--Logging enabled--&lt;/div&gt; </code></pre> <h3>The JavaScript</h3> <pre><code>function log(msg) { jQuery('#log').prepend(msg + '&lt;br/&gt;'); } function onPlayerStateChange(event) { switch(event.data) { case YT.PlayerState.ENDED: log('Video has ended.'); break; case YT.PlayerState.PLAYING: log('Video is playing.'); break; case YT.PlayerState.PAUSED: log('Video is paused.'); break; case YT.PlayerState.BUFFERING: log('Video is buffering.'); break; case YT.PlayerState.CUED: log('Video is cued.'); break; default: log('Unrecognized state.'); break; } } jQuery(document).ready(function($) { $('.video-thumb').click(function() { var vidId = $(this).attr('id'); $('#container').html('&lt;iframe id="player_'+vidId+ '" width="420" height="315" src="http://www.youtube.com/embed/'+ vidId+'?enablejsapi=1&amp;autoplay=1&amp;autohide=1&amp;showinfo=0" '+ 'frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'); new YT.Player('player_'+vidId, { events: { 'onStateChange': onPlayerStateChange } }); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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