0
votes

My application needs to support to play YouTube video and shows the first frame as Thumbnail. Since we need to keep our application running about playing video, therefore, in iOS 4.3.5, we used a method to embed a HTML link in a WebView. It works fine to play Video with YouTube player and it would return to my application upon finished.

Unfortunately, this method does not work. Any suggestion ?

My previous method is as follows:

NSString* embedHTML = @"body {background-color: transparent;color: white;} ";

NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];

NSLog(@"HTML = %@", html);
UIWebView* videoView = [[UIWebView alloc] initWithFrame:frame];  
videoView.backgroundColor = [UIColor clearColor];
[videoView loadHTMLString:html baseURL:nil];
[_supview addSubview:videoView];  
[videoView release];
2

2 Answers

0
votes

Use this:

- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
   NSString* embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0px\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
             width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";

   NSString* html = [NSString stringWithFormat:embedHTML, url, 
          frame.size.width, frame.size.height];
   NSLog(@"%@",html);
   if(youtube == nil) {
        youtube = [[UIWebView alloc] initWithFrame:frame];
        [self.view addSubview:youtube];
   }
  [youtube loadHTMLString:html baseURL:nil];
  [youtube setUserInteractionEnabled:YES];
}
0
votes

For iOS 5 or new apps use official syntax, see the link below it works very fine

http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html