I’m trying to get a simple video to play on an iPhone with iOS 4.3 and am running in to issues with dismissing the video player. Below is the code I have set up … I’m listening for three different notification events to help signal when the movie player and its parent view should exit, but none of those events seem to get fired. My callback method is never invoked.
NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"sample1" ofType:@"m4v"];
NSLog(@"Here is the movie path: %@", moviePath);
NSURL* movieUrl = [NSURL fileURLWithPath:moviePath];
NSLog(@"Will now try to play movie at the following url: %@", movieUrl);
self.mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpvc.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerDidExitFullscreenNotification object:self.mpvc.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerWillExitFullscreenNotification object:self.mpvc.moviePlayer];
[[self.mpvc moviePlayer] prepareToPlay];
[[self.mpvc moviePlayer] setShouldAutoplay:YES];
[[self.mpvc moviePlayer] setFullscreen:YES];
[self.mpvc.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview:self.mpvc.view];
Here is the sample code/example of NSNotification