Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config my server to providing the video file play with MPMoviePlayerViewController?

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.

like image 261
plucury Avatar asked Nov 13 '22 13:11

plucury


1 Answers

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.

like image 150
Jimmy Schementi Avatar answered Nov 15 '22 06:11

Jimmy Schementi