我正在使用以下代码尝试在我的应用中显示YouTube电影。出现视频播放器,显示控件一秒钟,然后电影播放器缩回。该应用程序不会崩溃。任何想法如何使这项工作?
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 :(得分:0)
您指向播放器的URL必须是支持的文件格式(例如H.264编码的mp4)。 Youtube网址是带有嵌入式播放器的HTML,用于加载实际的电影。在youtube中获得一个可玩的mp4是可能的,但不是那么简单(这可能已经改变了,上次我做这个是大约一年前)。 Youtube视频有一些防止热链接的保护,这使得实际的H.264 URL变得棘手。
要测试播放器,请尝试使用sample files apple提供的其中一个设置网络服务器。
至于获取youtube视频,它是可能的,它是棘手的(需要一些屏幕抓取),它是一个移动目标。
答案 1 :(得分:0)
我不记得我在哪里阅读,但我确实记得YouTube不允许您在MPMoviePlayerViewController
中播放视频 - 您必须将用户指向YouTube应用或使用{{ 1}}(因为他们详细here)。我想你可以做Felz的建议,但这会违反YouTube的政策。
希望这有帮助!