play youtube video in iphone or ipad

Hi,There may be requirement to play youtube video in iphone or ipad using xcode or objective c language
This functionality is very simple
Checkout the following code (This will only work in device not in simulator)
- (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:0\"><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];
    
    UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [webView loadHTMLString:html baseURL:nil];
    [self.view addSubview:webView];
}
- (void)viewDidLoad
{
    [self embedYouTube:@"http://www.youtube.com/watch?v=lzsBwnv_dAg&feature=player_embedded" frame:CGRectMake(0, 0, 320, 480)];
    [super viewDidLoad];
}

5 comments:

hi, thanks, but i have a problem, when i play the video and play "done", the app go to the main view of the app, and stop working, help!!! how i can press done, a continue playing with my app???

thanks

is it really works for any urls from you tube ?

Thanks for sharing as it is an excellent post would love to read your future post
-------------------------------------------------------------------------------
iPhone App Development :: && ::Mobile and Web Application Development

This comment has been removed by the author.

Post a Comment

Powered by Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More