title: iPhone - Play Youtube video by UIWebView
body: <p><strong>update</strong></p>
  
  <p>I have uploaded it to github, the link is <a href="https://github.com/ThinkChris/YouTubeDemo/blob/master/tabtest/FirstViewController.m" rel="nofollow">https://github.com/ThinkChris/YouTubeDemo/blob/master/tabtest/FirstViewController.m</a></p>
  
  <p>The requirement is:</p>
  
  <ol>
  <li>the app (based on tabviewcontroller) wont be rotated</li>
  <li>the embeded youtube video should get into fullscreen in portrait mode</li>
  <li>the fullscreen video can be rotated (portrait and landscape)</li>
  </ol>
  
  <hr>
  
  <p>Hi folks I have two blocks of codes to embed youtube video in a uiwebview, i notice that effects are different. aren't they all MPMoviePlayerController? why there are difference?</p>
  
  <p>code 1:video starts in portrait fullscreen, rotation restricted by viewcontroller (video cannot be retated if the viewcontroll cannot do so) </p>
  
  <pre><code>- (void)addYouTubeVideoWebView:(NSString*)url frame:(CGRect)frame 
  {
      // iframe
      url = @"http://www.youtube.com/embed/IQGhq0IlVok";
      NSString* embedHTML = @"\
      &lt;html&gt;\
          &lt;body style=\"margin:0\"&gt;\
              // HERERRRRRRRRRRRRRRRRRRRRRRRRRR
              &lt;iframe src=\"%@?showinfo=0\" width=\"%0.0f\" height=\"%0.0f\" frameborder=\"0\"&gt;&lt;/iframe&gt;\
          &lt;/body&gt;\
      &lt;/html&gt;\
      ";
  
      NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
  
      UIWebView * webView = [[UIWebView alloc] initWithFrame:frame]; 
      [webView loadHTMLString:html baseURL:nil];
      [self.view addSubview:webView];
  }
  </code></pre>
  
  <p>code 2: start in landscape fullscreen, can rotate to any direction by itself</p>
  
  <pre><code>- (void)addYouTubeVideoWebView:(NSString*)url frame:(CGRect)frame 
  {
      // embed
      url = @"http://www.youtube.com/watch?v=IQGhq0IlVok";
      NSString* embedHTML = @"\
      &lt;html&gt;\
          &lt;body style=\"margin:0\"&gt;\
              // HERERRRRRRRRRRRRRRRRRRRRRRRRRR
              &lt;embed type=\"application/x-shockwave-flash\" src=\"%@\" width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt;\
          &lt;/body&gt;\
      &lt;/html&gt;\
      ";
  
      NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
  
      UIWebView * webView = [[UIWebView alloc] initWithFrame:frame];  
      [webView loadHTMLString:html baseURL:nil];
      [self.view addSubview:webView];
  }
  </code></pre>