How to incorporate youtube into iPhone app?

岁酱吖の 提交于 2019-12-05 02:42:47

问题


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.


回答1:


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];
}



回答2:


  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



来源:https://stackoverflow.com/questions/7352631/how-to-incorporate-youtube-into-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!