简体   繁体   English

MPMoviePlayerController和HTTP Live Streaming

[英]MPMoviePlayerController and HTTP Live Streaming

every one. 每一个人。 I'm trying to figure out how to play live stream using MPMoviePlayerController. 我正试图弄清楚如何使用MPMoviePlayerController播放实时流。 For testing i'm using Apples test stream sample http://devimages.apple.com/iphone/samples/bipbopall.html . 对于测试我正在使用Apples测试流示例http://devimages.apple.com/iphone/samples/bipbopall.html It's perfectly working in UIWebView, but i can't make it work with MPMoviePlayerController. 它在UIWebView中完美地工作,但我不能使它与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. 实际上,控制器接收MPMoviePlayerPlaybackDidFinishNotification而不播放任何内容。 Where is the problem? 问题出在哪儿?

Your problem is probably with the URL. 您的问题可能与URL有关。 MPMoviePlayerController wants the URL directly to the file you want to play. MPMoviePlayerController希望URL直接指向您要播放的文件。 You are providing the URL for an HTML page which the movie player doesn't understand. 您正在提供电影播放器​​不理解的HTML页面的URL。 That is why it does work in UIWebView since a web browser understands HTML . 这就是为什么它在UIWebView中工作,因为Web浏览器理解HTML If you want more information about what's wrong you can check the error doing the following, quoted from Apple's documentation: 如果您想了解有关错误的更多信息,可以查看Apple公司文档中引用的错误:

To check for errors in URL loading, register for the MPMoviePlayerContentPreloadDidFinishNotification or MPMoviePlayerPlaybackDidFinishNotification notifications. 要检查URL加载中的错误,请注册MPMoviePlayerContentPreloadDidFinishNotification或MPMoviePlayerPlaybackDidFinishNotification通知。 On error, these notifications contain an NSError object available using the @"error" key in the notification's userInfo dictionary. 出错时,这些通知包含使用通知的userInfo字典中的@“error”键可用的NSError对象。

It would look something like: 它看起来像:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error) {
        NSLog(@"Did finish with error: %@", error);
    }
}

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 如果您想尝试播放该示例,可以尝试直接访问该流的URL,即: 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 您应该使用直接链接播放列表文件: http//devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];

NSNotification尝试object:mp而不是object:nil

@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 这是Apple Live Streaming的Apple文档,包括示例代码http://developer.apple.com/library/ios/search/index.php?Search=HTTP+Live+Streaming+Overview

Dung. 粪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM