title: YouTube onStateChange event is not working properly
body: <p>I was wondering why YouTube onPlayerStateChange is not working properly.</p>
  
  <p>In that scenario I don't get any alert message (or any other event) when the youtube video ended.</p>
  
  <p>Any Idea ?</p>
  
  <pre><code>&lt;!doctype html&gt;
  
  &lt;html lang="en"&gt;
  &lt;body&gt;
  
  &lt;iframe src=""&gt;&lt;/iframe&gt;
  &lt;script src="js/jquery.js"&gt;&lt;/script&gt;
  &lt;script src="http://www.youtube.com/iframe_api"&gt;&lt;/script&gt;
  &lt;script&gt;    
  function onPlayerStateChange(event) {
      switch(event.data) {
          case YT.PlayerState.ENDED:
              alert('VIDEO IS ENDED'); // &lt;&lt;&lt;--- THIS IS NOT WORKING
              break;
      }
  }
  
  jQuery(document).ready(function($) {
      var vidId = 'uIv6u7pdR5I';
      $('iframe').attr('src', "https://youtube.googleapis.com/v/" + vidId);
          new YT.Player('player_'+vidId, {
              events: {
                  'onReady': onPlayerReady,
                  'onStateChange': onPlayerStateChange
              },
              playerVars: { autohide: 1, showinfo: 0 }
          });
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>