Search code examples
iphoneobjective-ccocoa-touchuiwebviewyoutube

How to incorporate youtube into iPhone app?


I have an iPhone app and I want one view to push to a UIWebView maybe that shows search results of youtube videos for a particular search term. Then I want the user to be able to select the video and play it in app.

I've looked at the youtube tutorials but can't seem to get a good grasp as to how to do this.


Solution

  • Here is a method I use in a view controller with a UIWebView :

    - (void)embedYouTubeWithURLString:(NSString *)urlStr {
        CGFloat w = webView.frame.size.width;
        CGFloat h = webView.frame.size.height;
        NSString *embed = [NSString stringWithFormat:@"<html><head><meta name=\"viewport\""\
        " content=\"initial-scale=1.0, user-scalable=no, width=%0.0f\"/></head><body "\
        "style=\"background-color:transparent;margin-top:0px;margin-left:0px\"><div><object "\
        "width=\"%0.0f\" height=\"%0.0f\"><param name=\"movie\" value=\"%@\" /><param name=\"wmode"\
        "\"value=\"transparent\" /><param name=\"allowFullScreen\" value=\"true\" /><param"\
        " name=\"quality\" value=\"high\" /><embed src=\"%@\" type=\"application/x-shockwave-flash"\
        "\" allowfullscreen=\"true\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\" />"\
        "</object></div></body></html>", w, w, h, urlStr, urlStr, w, h];
        [webView loadHTMLString:embed baseURL:nil];
    }