How to incorporate youtube into iPhone app?

2019-04-01 07:34发布

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.

2条回答
来,给爷笑一个
2楼-- · 2019-04-01 07:55

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];
}
查看更多
Rolldiameter
3楼-- · 2019-04-01 07:57
  1. Call YouTube Video Search Web Service.
  2. ParseXML Returned from Search.
  3. Build a UITableView from Results - Or, build a javascript UI in UIWebView.
  4. Play selected video using this method:

http://iosdevelopertips.com/video/display-youtube-videos-without-exiting-your-application.html

查看更多
登录 后发表回答