How to config my server to providing the video fil

2019-02-17 14:28发布

I want to using MPMoviePlayerViewController to play the video file on my server. But It not works.

My iOS code are as bellow:

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];
}

And I got the error message from NSNotification is:

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

Then I changed the URL to

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

But it works well. Since the two files are exactly the same file. I think there must be something wrong with my remote server. And here is the response headers from my server :

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)

In additional, The video can play on my macbook with Chrome/Safari, But it can't play on iPhone with browsers too.

2条回答
在下西门庆
2楼-- · 2019-02-17 14:49

After correcting the content URL, if the Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\" error still happens, it may be because your HTTP server does not support byte-range requests. See MPMoviePlayerPlaybackDidFinishNotification is called immediately for more information.

查看更多
萌系小妹纸
3楼-- · 2019-02-17 14:50

You are pointing your MPMoviePlayerController at 127.0.0.1, which is the current device's IP. So your iOS app is looking for a web server hosting that file on your iPhone. Your code looks fine otherwise, you've just got to host the .mov somewhere valid.

查看更多
登录 后发表回答