title: How to control the youtube flash player with c#?
body: <p>My goal is to make a open source YouTube player that can be controlled via global media keys.
  The global key issue I got it covered but the communication between the YouTube player and my Windows Forms application just doesn't work for some reason.</p>
  <p>So far this is what I have:</p>
  <pre><code>private AxShockwaveFlashObjects.AxShockwaveFlash player;
  player.movie = &quot;http://youtube.googleapis.com/v/9bZkp7q19f0&quot;
  ...
  private void playBtn_Click(object sender, EventArgs e)
  {
      player.CallFunction(&quot;&lt;invoke name=\&quot;playVideo\&quot; returntype=\&quot;xml\&quot;&gt;&lt;/invoke&gt;&quot;);
  }
  </code></pre>
  <p>Unfortunately this returns:</p>
  <pre><code>&quot;Error HRESULT E_FAIL has been returned from a call to a COM component.&quot;
  </code></pre>
  <p>What am I missing? Should I load a different URL?
  <br/><a href="https://developers.google.com/youtube/articles/youtube_as3_chromeless" rel="noreferrer">The documentation</a> states that YouTube player uses <strong>ExternalInterface class</strong> to control it from JavaScript or AS3 so <a href="http://bojolais.livejournal.com/251383.html" rel="noreferrer">it should work with c#</a>.</p>
  <br/>
  <h3>UPDATED:</h3>
  <hr />
  <p>Method used to embed the player: <a href="http://www.youtube.com/watch?v=kg-z8JfOIKw" rel="noreferrer">http://www.youtube.com/watch?v=kg-z8JfOIKw</a> </p>
  <p>Also tried to use the <a href="https://developers.google.com/youtube/js_api_reference" rel="noreferrer">JavaScript-API</a> in the WebBrowser control but no luck (player just didn't respond to JavaScript commands, tried even to set <code>WebBrowser.url</code> to a <a href="https://developers.google.com/youtube/youtube_player_demo" rel="noreferrer">working demo</a>, all that I succeeded is to get the <code>onYouTubePlayerReady()</code> to fire using the simple <a href="https://developers.google.com/youtube/youtube_player_demo#object-embed-code-header" rel="noreferrer">embedded object version</a> )</p>
  <p>I think there might be some security issues that I'm overseeing, don't know. </p>
  <br/>
  <h3>UPDATE 2:</h3>
  <hr />
  <p>fond solution, see my <a href="https://stackoverflow.com/questions/13260361/how-to-control-the-youtube-flash-player-with-c/16508605?noredirect=1#answer-13604903">answer</a> below.</p>