【问题标题】:how to play youtube video in iphone application?如何在 iphone 应用程序中播放 youtube 视频?
【发布时间】:2011-04-25 05:06:55
【问题描述】:

我想在我的应用程序中使用 url 播放 Youtube 视频。我尝试了以下代码,但它不起作用。

   NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/v/pGqraZN5U0k&amp"];
   MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
   if (moviePlayer)
   {
     [self.moviePlayer play];
   }

请帮帮我。

提前致谢。

【问题讨论】:

    标签: iphone-sdk-3.0 ios-simulator


    【解决方案1】:

    YouTube 视频不能直接在 MPMoviePlayerController 中播放。您必须启动 YouTube 应用或创建 UIWebView 来显示视频。请参阅以下问题:

    Play youtube videos with MPMoviePlayerController

    【讨论】:

      【解决方案2】:
      NSString *youTubeVideoHTML = @"<html><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:youTubeVideoHTML, youtube video link, self.webView.frame.size.width, self.webView.frame.size.height];
      NSLog(@"html %@",html);
      [self.webView loadHTMLString:html baseURL:nil];
      

      【讨论】:

        猜你喜欢
        • 2011-11-16
        • 2012-04-05
        • 2014-02-01
        • 1970-01-01
        • 2011-08-27
        • 2018-08-06
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        相关资源
        最近更新 更多