MPMoviePlayerController 和 HTTP 直播
每个人。我试图弄清楚如何使用 MPMoviePlayerController 播放实时流。为了进行测试,我使用苹果测试流示例 http://devimages.apple.com/iphone /samples/bipbopall.html。 它在 UIWebView 中完美工作,但我无法使其与 MPMoviePlayerController 一起工作。这是我的一段代码:
NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbopall.html"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
实际上控制器收到 MPMoviePlayerPlaybackDidFinishNotification 而不播放任何内容。问题出在哪里?
every one. I'm trying to figure out how to play live stream using MPMoviePlayerController. For testing i'm using Apples test stream sample http://devimages.apple.com/iphone/samples/bipbopall.html.
It's perfectly working in UIWebView, but i can't make it work with MPMoviePlayerController. There is my piece of code:
NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbopall.html"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
Actually the controller recieves MPMoviePlayerPlaybackDidFinishNotification without playing anything. Where is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的问题可能出在 URL 上。
MPMoviePlayerController
想要直接指向您要播放的文件的 URL。您提供的HTML
页面的 URL 是电影播放器无法理解的。这就是它在UIWebView
中工作的原因,因为网络浏览器可以理解HTML
。如果您想了解有关问题的更多信息,您可以执行以下操作来检查错误(引用自 Apple 文档):它看起来像:
如果您想尝试播放该示例,您可以尝试直接访问流的 URL,该 URL 为: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
Your problem is probably with the URL.
MPMoviePlayerController
wants the URL directly to the file you want to play. You are providing the URL for anHTML
page which the movie player doesn't understand. That is why it does work inUIWebView
since a web browser understandsHTML
. If you want more information about what's wrong you can check the error doing the following, quoted from Apple's documentation:It would look something like:
If you want to try and play that sample you can try and access the URL for the stream directly, which would be: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
您应该使用直接链接来播放列表文件: http://devimages.apple.com /iphone/samples/bipbop/bipbopall.m3u8
You should use direct link to play list file: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
在您的
NSNotification
中尝试使用object:mp
而不是object:nil
Try
object:mp
instead ofobject:nil
in yourNSNotification
@Andrew:
这是 HTTP Live Streaming 的 Apple 文档,包括示例代码 http://developer.apple.com/library/ios/search/index.php?Search=HTTP+Live+Streaming+Overview
粪。
@Andrew:
Here is Apple documentation of HTTP Live Streaming including sample code http://developer.apple.com/library/ios/search/index.php?Search=HTTP+Live+Streaming+Overview
Dung.