使用MPMoviePlayerController播放YouTube视频 [英] Playing youtube video with MPMoviePlayerController
问题描述
我一直在使用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屋!