如何用MPMoviePlayerController播放video

我正在使用此代码从苹果网站播放videostream

- (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被立即调用并且logging错误消息:

完成错误:错误域= MediaPlayerErrorDomain代码= -11800“操作无法完成”UserInfo = 0x78d25d0 {NSLocalizedDescription =操作无法完成}

我怎样才能解决这个错误?

您没有将此标记为iOS,但MPMoviePlayer仅适用于iOS。 这应该适用于在iOS上播放的video。 不幸的是你试图播放的video不是iOS兼容的。 试试这个url:

 http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_ipad_vod_ref.mov