Monday, January 3, 2011

How to fetch a you tube video on iphone or ipad.

Create a view base application and add a webView on it and call this html string to get the video of the desired url of youtube you want........
you can use this part of code .....

    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, urlString];
    UIWebView *videoWebView = [[UIWebView alloc] initWithFrame:frame];
    [videoView loadHTMLString:html baseURL:nil];
   //here u can add this to your own calayer or on any view you want.....   
    [videoWebView release];

5 comments:

  1. Thanks dude it's all running for me it works...

    ReplyDelete
  2. Great! Really useful. Thanks

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. hey i am facing problems in this line:
    UIWebView *videoWebView = [[UIWebView alloc] initWithFrame:frame];
    compiler says frame not a struct or union.
    Please reply.I feel helpless.

    ReplyDelete
  5. Dude actually your frame variable is not initialized.You need to initialize as follows....
    frame=CGRectMake(xcoord,ycoord,width,height);

    ReplyDelete