我想用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与浏览器也无法播放。