MPMoviePlayerController和HTTP Live Streaming [英] MPMoviePlayerController and HTTP Live Streaming
问题描述
它完全适用于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而不播放任何内容。哪里有问题?
您的问题可能与网址有关。 MPMoviePlayerController
希望URL直接指向您要播放的文件。您正在提供电影播放器无法理解的 HTML
页面的网址。这就是为什么它在 UIWebView
中工作的原因,因为Web浏览器理解 HTML
。如果您想了解有关错误的更多信息,可以查看以下错误,请参阅Apple的文档:
检查URL中的错误loading,
注册
MPMoviePlayerContentPreloadDidFinishNotification
或
MPMoviePlayerPlaybackDidFinishNotification
通知。出错时,这些
通知包含NSError
对象,该对象使用通知的userInfo
字典中的@error
键。
它看起来像:
- (void)moviePlayBackDidFinish:(NSNotification *)通知{
NSError * error = [[notification userInfo] objectForKey:@error];
if(error){
NSLog(@完成错误:%@,错误);
}
}
如果你想尝试播放那个样本你可以尝试直接访问流的URL,即: http://devimages.apple.com/ iphone / samples / bipbop / bipbopall.m3u8
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?
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 an HTML
page which the movie player doesn't understand. That is why it does work in UIWebView
since a web browser understands HTML
. If you want more information about what's wrong you can check the error doing the following, quoted from Apple's documentation:
To check for errors in URL loading, register for the MPMoviePlayerContentPreloadDidFinishNotification or MPMoviePlayerPlaybackDidFinishNotification notifications. On error, these notifications contain an NSError object available using the @"error" key in the notification’s userInfo dictionary.
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
这篇关于MPMoviePlayerController和HTTP Live Streaming的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!