【问题标题】:How to play youtube video using MPMoviePlayerController?如何使用 MPMoviePlayerController 播放 youtube 视频?
【发布时间】:2016-07-26 16:30:21
【问题描述】:

我想播放 youtube 网址的视频。 我正在使用下面的代码,但它不起作用。

-(void)playVideoFromURL
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%s","https://www.youtube.com/embed/96ReVjMAXEE?autoplay=1&vq=small"]];
    self.videoController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.videoController setControlStyle:MPMovieControlStyleNone];
    self.videoController.repeatMode=MPMovieRepeatModeOne;
    self.videoController.fullscreen=YES;
    self.videoController.scalingMode=MPMovieScalingModeFill;
    self.videoController.view.frame=CGRectMake(0,0,self.videoplayview.frame.size.width, self.videoplayview.frame.size.height);
    [self.videoplayview addSubview:self.videoController.view];
    [self.videoController play];
}

【问题讨论】:

  • 您面临的问题是什么?
  • 我认为你不能在任何播放器中播放 youtube 视频,除了 youtube 自己的。他们有一个 SDK,您需要使用他们提供的 youtube 播放器来播放来自 youtube 的视频。
  • 不可能使用youtube-iso-player-helperMPMoviePlayerController
  • 我也有同样的问题。你解决了吗?如果是的话,请指导我完成这个。还是您使用了其他场景、方法或播放器?

标签: ios objective-c youtube video-streaming


【解决方案1】:

很遗憾,无法使用 MPMoviePlayerController 直接播放 youtube 视频,因为 youtube 不会公开指向视频文件的直接链接。

在您自己的应用程序中播放 youtube 视频的唯一方法是使用 Youtube 的 embed 标签创建一个 UIWebView,用于您想要作为 UIWebView 内容播放的电影。 UIWebView 将检测到嵌入的对象是一个 Youtube 链接,并且 web 视图的内容将是视频的 youtube 预览。当您的用户单击预览时,视频将显示在 MPMoviePlayerController 中。

【讨论】:

    【解决方案2】:

    您无法在 MPMoviePlayerController 中播放 YouTube 视频 URL。为此,您必须使用

    youtube-iso-player-helper - 但您无法在 youtube-iso-player-helper 中播放私人视频网址

    XCDYoutubeKit - 这违反了 YouTube 条款和服务。

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 2012-05-11
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      相关资源
      最近更新 更多