Hi to all i've got a strange behavior with an MPMoviePlayerController
the odds time i play the video it works... the evens no!
as said here MPMoviePlayerController will play once, then throw an error the problem could be the url, but i'm not able to find a solution..
Here is my code
NSURL *myUrl = [[NSURL alloc] initWithString:CDNRequest];
moviecontroller = [[MMRMovieViewController alloc] initWithContentURL:myUrl];
[[moviecontroller moviePlayer] setScalingMode:MPMovieScalingModeAspectFit];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification object:[moviecontroller moviePlayer]];
[self moviecontroller];
MMRMovieViewController is a view controller which just extends MPMoviePlayerViewController. and here is the playbackFinished method
- (void)playbackFinished:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"playback ended");
break;
case MPMovieFinishReasonPlaybackError:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"playback error");
NSError* error = [[notification userInfo] valueForKey:@"error"];
NSLog(@"error=%@", error);
break;
case MPMovieFinishReasonUserExited:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"user exited");
break;
default:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
break;
}
if (moviePlayer == TRUE) {
[moviePlayer setFullscreen:NO animated:YES];
}
[moviePlayer stop];
[moviePlayer removeFromSuperview];
moviePlayer = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
The error log says: "rror = "Error Domain=MediaPlayerErrorDomain Code=-12847 \"This movie format is not supported.\" UserInfo=0x5b60030 {NSLocalizedDescription=This movie format is not supported.}" But sometimes it goes! so it can't be this the reason!
Any help is appreciated!
Thank You!