2011-02-08 72 views
0

我正在使用以下代码尝试在我的应用中显示YouTube电影。出现视频播放器,显示一秒钟的控件,然后电影播放器​​收回。该应用程序不会崩溃。任何想法如何使这项工作?在MPMoviePlayerViewController中显示YouTube电影 - iPhone

MPMoviePlayerViewController *mpViewController = 
[[MPMoviePlayerViewController alloc] 
initWithContentURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=VKsVSBhSwJg"]]; 

[mpViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]; 

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 

[self presentMoviePlayerViewControllerAnimated:mpViewController]; 

[mpViewController release]; 

回答

0

我不记得我在哪里看过它,但我确实记得YouTube不允许您播放MPMoviePlayerViewController中的视频 - 您必须将用户指向YouTube应用或使用UIWebView(因为它们详细here)。我想你可能做Felz建议,但它会违反YouTube的政策。

希望这会有所帮助!

+0

啊,我已经读过了,但它的日期是2009年,所以我认为它现在可能已经升级了。 – Chris 2011-02-08 19:56:17

0

您指向播放器的URL必须是支持的文件格式(例如H.264编码的mp4)。 Youtube网址是带有加载实际电影的嵌入式播放器的HTML。在YouTube上获得可播放的mp4是可能的,但不是那么简单(这可能已经改变了,上一次我做了大约一年前)。 Youtube视频有一些防范盗链的措施,让实际的H.264网址变得棘手。

要测试播放器,请尝试使用苹果提供的sample files之一设置网络服务器。

至于获得youtube视频,这是可能的,它是棘手的(需要一些屏幕抓取),它是一个移动的目标。

相关问题