title: How to call back into android code from Youtube IFRAME API
body: <p>I am loading an embedded youtube player in my android webview as follows:</p>
  
  <pre><code>void loadYTVideoInWebView(String code) {
  String frameVideo = "&lt;html&gt;&lt;body style='margin:0px;padding:0px;'&gt;\n" +
          "        &lt;script type='text/javascript' src='http://www.youtube.com/iframe_api'&gt;&lt;/script&gt;&lt;script type='text/javascript'&gt;\n" +
          "                var player;\n" +
          "        function onYouTubeIframeAPIReady()\n" +
          "        {player=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}\n" +
          "        function onPlayerReady(event){player.playVideo();}\n" +
          "        &lt;/script&gt;\n" +
          "        &lt;iframe id='playerId' type='text/html' width='400' height='360'\n" +
          "        src='https://www.youtube.com/embed/"+code+"?enablejsapi=1&amp;autoplay=1' frameborder='0'&gt;\n" +
          "        &lt;/body&gt;&lt;/html&gt;";
  mWebView.loadDataWithBaseURL("http://www.youtube.com", frameVideo, "text/html", "utf-8", null);}
  </code></pre>
  
  <p>Once the video finishes playing, I want to send a notification to the Android code. I know that we can detect the video end in the Javascript using something like:</p>
  
  <pre><code>function onPlayerStateChange(event) {        
          if(event.data === 0) {          
              alert('done');
          }
      }
  </code></pre>
  
  <p>I wanted to know if it is possible to call back into the android code from here.</p>