Hi all.
I am loading up a video file in an iPad application using the MPMoviePlayerViewController. Basically, click the button, watch the video. It works great, unless you press the "Aspect Ratio" button (the one which looks like two arrows) which normally sets the video to autofit. In this case, it just closes the movie, and procs a MPMoviePlayerDidFinishNotification for some odd reason.
Here is some of the code:
-(IBAction)clicked:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Video1" ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:path];
[self playMovieWithUrl:url];
}
-(void)playMovieWithUrl:(NSURL *)url
{
if(moviePlayer == nil)
{
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
}
else
{
[moviePlayer.moviePlayer setContentURL:url];
}
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer.moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
[window addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];
}
-(void)movieDidFinish:(NSNotification *)notification
{
NSDictionary *dict = [notification userInfo];
NSLog(@"notification reason: %@", [dict objectForKey:@"MPMoviePlayerPlaybackDidFinishReasonUserInfoKey"]];
[moviePlayer.moviePlayer stop];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
moviePlayer = nil;
}
The NSLog statement reveals that the movie is finishing due to an error. However, I cannot seem to figure out why pressing that button causes an error, or how to rectify it. The simplest solution is to just remove that button, but that doesn't seem to be possible either - at least not without subclassing the MoviePlayerController, which I think is overkill.
Also, note that it is in the application delegate. I realise that is probably bad, but this app is a little test and there is no point overcomplicating it. I also experienced the same issue with the controller in a proper view anyway!
Also, I did notice that if I set the control style to embedded then pressing that button causes some flashing to occur on screen, but stops the closing of the video. It still isn't right though.
Anyone got any ideas? I'm stumped!
Thanks in advance! ~ Andrew
Edit: Since posting, I tried again by putting it into an actual view of its own, and using a MPMoviePlayerViewController (which I present modally). It doesn't work any better.
...is anybody here? :P