title: Embedding Youtube videos in iOS
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5117617/embedding-youtube-videos-on-ios">Embedding YouTube videos on iOS</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to embed youtube videos on iOS, so that when a user clicks a button, youtube video is shown without leavign the app, and once the video is done, the user is returned to the app. I found a tutorial online showing how to do this, and i followed it. I create a YouTubeView:</p>
  
  <pre><code>#import "YouTubeView.h"
  
  
  @implementation YouTubeView
  
  - (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame {
      self = [super init];
      if (self) 
      {
          // Create webview with requested frame size
          self = [[UIWebView alloc] initWithFrame:frame];
  
          // HTML to embed YouTube video
          NSString *youTubeVideoHTML = @"&lt;html&gt;&lt;head&gt;\
          &lt;body style=\"margin:0\"&gt;\
          &lt;embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
          width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt;\
          &lt;/body&gt;&lt;/html&gt;";
  
          // Populate HTML with the URL and requested frame size
          NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
  
          // Load the html into the webview
          [self loadHTMLString:html baseURL:nil];
      }
      return self;  
  }
  
  #pragma mark -
  #pragma mark Cleanup
  
  - (void)dealloc 
  {
      [super dealloc];
  }
  
  @end
  </code></pre>
  
  <p>and I am instantiating it like this: (case 2)</p>
  
  <pre><code>- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
      SongInfoTableVC *infoVC;
      YouTubeView *youTubeView;
      switch (buttonIndex) {
          case 0:
              NSLog(@"hello");
              [self setLyrics];
              break;
          case 1:
              infoVC = [[SongInfoTableVC alloc] initWithStyle:UITableViewStyleGrouped];
              [infoVC setBook:data];
              [infoVC setTitle:@"Song Info"];
              [[self navigationController] pushViewController:infoVC animated:YES];
              [infoVC release];
              break;
          case 2:
              youTubeView = [[YouTubeView alloc] 
                                          initWithStringAsURL:@"http://www.youtube.com/watch?v=xli2E2i8GZ4" 
                                          frame:CGRectMake(0, 0, 320, 480)];
  
              [[[self navigationController] view] addSubview:youTubeView];
              break;
          default:
              break;
      }
  }
  </code></pre>
  
  <p>but this bring up a blank white screen. What am I doing wrong?
  Here's the screenshot:
  <img src="https://i.stack.imgur.com/gnNYS.png" alt="enter image description here"></p>
  
  <p>Thanks</p>