如何configuration我的服务器提供video文件播放与MPMoviePlayerViewController?

我想使用MPMoviePlayerViewController播放我的服务器上的video文件。 但它不起作用。

我的iOS代码如下:

NSURL *mediaURL = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"http://127.0.0.1:3000/media/%@", @"sample_iTunes.mov"]]; self.player = [[MPMoviePlayerViewController alloc] initWithContentURL: mediaURL]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer]; self.player.moviePlayer.shouldAutoplay = YES; self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; [self presentMoviePlayerViewControllerAnimated:self.player]; [self.player.moviePlayer prepareToPlay]; [self.player.moviePlayer play]; -(void)movieFinishedCallback:(NSNotification*)aNotification { NSLog(@"%@",[aNotification valueForKey:@"userInfo"]); MPMoviePlayerViewController* theMovie = [aNotification object]; } 

而我从NSNotification得到的错误信息是:

 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 1; error = "Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\" UserInfo=0x1d51b640 {NSLocalizedDescription=Operation Stopped}"; 

然后我改变了URL

 http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov 

但它运作良好。 由于这两个文件是完全相同的文件。 我认为我的远程服务器肯定有问题。 这里是我的服务器的响应标题:

 HTTP/1.1 200 OK Content-Length: 3284257 Date: Mon, 14 Jan 2013 06:06:12 GMT Last-Modified: Sun, 13 Jan 2013 10:44:02 +0000 Accept-Ranges: bytes Content-Type: video/quicktime Connection: close Server: Jetty(7.6.1.v20120215) 

此外,video可以在Chrome / Safari上在我的MacBook上播放,但是也不能在带有浏览器的iPhone上播放。

纠正内容URL后,如果Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\"错误仍然发生,这可能是因为您的HTTP服务器不支持字节范围请求。 请参阅立即调用MPMoviePlayerPlaybackDidFinishNotification以获取更多信息。

您正在将您的MPMoviePlayerController指向127.0.0.1,这是当前设备的IP。 所以你的iOS应用程序正在寻找一个你的iPhone 托pipe该文件的Web服务器。 否则,你的代码看起来很好,你只需要将.mov放在某个有效的地方。