我想使用 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 上用浏览器播放。