0

I'm trying to play video with the following code:

UIGraphicsBeginImageContext(CGSizeMake(1,1));

self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.blablabla.org/app/video/v5_seq8_v2_360p.mp4"]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer];

[self presentMoviePlayerViewControllerAnimated:self.player];

UIGraphicsEndImageContext();

[self.player.moviePlayer prepareToPlay];
[self.player.moviePlayer play];

The sel.player closes and didFinishPlayback: method is called instantly. I retrieve the error from the notification like this:

NSLog(@"Error %@", notification.userInfo[@"error"]);

and it looks like the following:

Domain=MediaPlayerErrorDomain Code=-11850 "Operation Stopped"

but when i open the url in a browser then the video starts playing without any problems. What can be the cause of this error? Thanks

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161

3 Answers3

0

I'am not sure why, but with remote url's I realized in a past project that you need to add the observer without object as reference.... If you ask me why, I am not sure. Try adding the observer with nil as object...

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
Calleth 'Zion'
  • 613
  • 3
  • 15
0

If the video plays on your desktop machine, but not iOS (either in-app or in Safari), it's most likely because the HTTP server does not support byte-range requests. If the HTTP server does not support byte-range requests, iOS will not play the video. This differs from Safari on OS X, which plays the video regardless.

From the Safari Web Content Documentation:

HTTP servers hosting media files for iOS must support byte-range requests, which iOS uses to perform random access in media playback. (Byte-range support is also known as content-range or partial-range support.) Most, but not all, HTTP 1.1 servers already support byte-range requests.

Also, the HTTP server must provide a valid Content-Type header (the URL above also enumerates the valid MIME types). iOS will not play the video if the MIME type is invalid or missing.

Jimmy Schementi
  • 1,239
  • 8
  • 17
-1

Try insert this:

[[NSNotificationCenter defaultCenter] removeObserver: self.player
                                                name: MPMoviePlayerPlaybackDidFinishNotification
                                              object: self.player.moviePlayer];

before

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer]; 
stosha
  • 2,108
  • 2
  • 27
  • 29