如何使用MPMoviePlayerController播放视频 [英] How to play a video with MPMoviePlayerController
问题描述
我正在使用此代码播放来自苹果网站的视频流
I'm using this code to play a video streaming from the apple site
- (IBAction)playMovie:(UIButton *)sender {
NSLog(@"start playing");
//NSURL *url = [NSURL URLWithString:@"http://spatie.be/test.mov"];
NSURL *url = [NSURL URLWithString:@"http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov"];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSError *error = [[notification userInfo] objectForKey:@"error"];
if (error) {
NSLog(@"Did finish with error: %@", error);
}
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
调用playMovie时, moviePlayBackDidFinish
被立即调用并记录错误消息:
When playMovie is invoked, moviePlayBackDidFinish
is immediatelty called and the error message is logged:
完成错误:错误Domain = MediaPlayerErrorDomain Code = -11800
操作无法完成UserInfo = 0x78d25d0
{NSLocalizedDescription =操作无法完成}
Did finish with error: Error Domain=MediaPlayerErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x78d25d0 {NSLocalizedDescription=The operation could not be completed}
如何解决此错误?
推荐答案
您没有将此标记为iOS,但MPMoviePlayer仅限iOS。这应该适用于将在iOS上播放的视频。不幸的是,您尝试播放的视频与iOS不兼容。试试这个网址:
You didn't tag this as iOS, but MPMoviePlayer is iOS only. This should work just fine with a video that will play on iOS. Unfortunately the video you are trying to play is not iOS compatible. Try this URL:
http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_ipad_vod_ref.mov
这篇关于如何使用MPMoviePlayerController播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!