使用 MPMoviePlayerController 播放 youtube 视频 [英] Playing youtube video with MPMoviePlayerController

查看:18
本文介绍了使用 MPMoviePlayerController 播放 youtube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我长期以来一直使用 html 字符串通过 UIWebView 播放 youtube 视频,问题是我想在播放状态更改时获得通知.我决定创建一个 MPMoviePlayerController 并通过它播放 youtube 视频,但似乎无法让它工作.我在 viewdidload 中使用以下代码:

i've been using an html string for a long period for playing youtube videos through an UIWebView, the problem is i want to get notifications with playbackstate changed. i've decided to create an MPMoviePlayerController and play the youtube video through this, but cant seem to make it work. i'm using following code in viewdidload:

NSString *urlAddress = @"http://www.youtube.com/watch?v=m01MYOpbdIk";
NSURL *url = [NSURL URLWithString:urlAddress];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
movie.scalingMode=MPMovieScalingModeAspectFill;
movie.view.frame = CGRectMake(0.0, 0.0, width, height);
[self.view addSubview:movie.view];
[movie play];

给我这个错误:

_itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
 }

推荐答案

使用自定义LBYouTubePlayerViewController

Make use of custom LBYouTubePlayerViewController

它是MPMoviePlayerViewController的子类.

LBYouTubeView 只是一个能够在 MPMoviePlayerController 中显示 YouTube 视频的小视图.您甚至可以在高质量和标准质量流之间进行选择.

LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController. You even have the choice between high-quality and standard quality stream.

它只是加载 YouTube 移动网站的 HTML 代码并在脚本标签中查找数据.

It just loads the HTML code of YouTube's mobile website and looks for the data in the script tag.

LBYouTubeView 不使用 UIWebView 这使得它更快,看起来更干净.

LBYouTubeView doesn't use UIWebView which makes it faster and look cleaner.

这篇关于使用 MPMoviePlayerController 播放 youtube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆