我想使用MPMoviePlayerViewController在我的服务器上播放视频文件。但它不起作用。
我的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}";
然后我将网址更改为
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)
此外,视频可以在我的Macbook上使用Chrome / Safari播放,但它也无法在带浏览器的iPhone上播放。
答案 0 :(得分:1)
更正内容网址后,如果仍然发生Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\"
错误,可能是因为您的HTTP服务器不支持字节范围请求。有关详细信息,请参阅MPMoviePlayerPlaybackDidFinishNotification is called immediately。
答案 1 :(得分:0)
您将MPMoviePlayerController指向127.0.0.1,这是当前设备的IP。所以你的iOS应用程序正在寻找一个托管 on 你的iPhone上的文件的网络服务器。你的代码看起来很好,否则,你必须在某个地方托管.mov。