使用MPMoviePlayerController而不是UIWebView播放YouTube视频 [英] Play YouTube videos with MPMoviePlayerController instead of UIWebView

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

问题描述

我正在尝试使用MPMoviePlayerController来传输一些youTube视频,但我遇到了一些问题。我正在使用的代码非常简单,我可以通过将URL传递给initWithContentURL来播放.m4v视频。当我启动电影播放器​​时,播放器出现但在大约20秒后消失。当我在模拟器中尝试它时,我得到一个警告视图,说明服务器配置不正确。我是否需要通过URL传递来自谷歌的特定类型的视频源?

I'm trying to stream some youTube videos using the MPMoviePlayerController but I'm having some problems. The code I'm using is pretty simple and I can play .m4v videos by passing a URL to initWithContentURL. When I launch the movie player the player comes up but just goes away after about 20 seconds. When I try it in the simulator I get an alert view that says the server is not configured correctly. Is there an argument I need to pass with the URL to get a specific type of video feed from google?

NSURL *videoURL = [NSURL URLWithString:@"http://www.youtube.com/v/HGd9qAfpZio&hl=en_US&fs=1&"];
MPMoviePlayerController *moviePlayer;
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

[moviePlayer play];

我还尝试了以下网址的
http://www.youtube.com/watch?v=HGd9qAfpZio

I've also tried the following URL's http://www.youtube.com/watch?v=HGd9qAfpZio

我也看到了参数& format = 1并尝试将其添加到两个字符串的末尾但没有运气。

I have also seen the argument &format=1 and tried to add that to the end of both of the strings but no luck.

推荐答案

在你自己的应用程序中播放YouTube视频的唯一方法是使用来自Youtube的embed标签为你想要播放的电影创建一个 UIWebView 作为 UIWebView的内容。 UIWebView 将检测到嵌入对象是Youtube链接,并且Web视图的内容将是视频的youtube预览。当您的用户点击预览时,视频将显示在MPMoviePlayerController中。这是Muxecoid提供的链接中描述的技术(如何在应用程序中播放youtube视频),这是(据我所知)在应用程序中播放YouTube视频的唯一方法。您仍然可以通过将youtube网址传递到 - [UIApplication openURL:] 来启动Youtube应用程序,但当然这会关闭您自己的应用程序,这通常是不受欢迎的。

The only way to have a youtube video play inside your own app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. This is the technique described at the link that Muxecoid provided (how to play youtube videos within an application), and this is (as far as I know of) the only way to have a youtube video play within an application. You can still have the Youtube application launch by passing the youtube URL to -[UIApplication openURL:], but of course this closes your own application which is often undesirable.

不幸的是,没有办法用 MPMoviePlayerController 直接播放youtube视频,因为youtube不会公开指向视频文件的直接链接。

Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.

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

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