I have a table view to select audio or video. If I select 'video' I push a view to play the video.
Code:
if(indexPath.row == 1) {
if(videoPlayer == nil) {
videoPlayer = [[VideoPlayerViewController alloc] initWithNibName:@"VideoPlayerViewController" bundle:[NSBundle mainBundle]];
}
[self.navigationController pushViewController:videoPlayer animated:YES];
videoPlayer = nil;
[videoPlayer release];
}
The pushed view has these lines of code:
Code:
- (void)viewDidLoad {
if(self.moviePlayer == nil) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
self.movieURL = [NSURL fileURLWithPath:moviePath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL];
self.moviePlayer.scalingMode = MPMovieScalingModeNone;
self.moviePlayer.movieControlMode = MPMovieControlModeDefault;
self.moviePlayer.backgroundColor = [UIColor blackColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.moviePlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
[self.moviePlayer play];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.moviePlayer stop];
}
The first time I load the movie it plays fine in landscape orientation. The second time I load the movie the screen stays black and the video controls are in portrait mode (see screenshots).
First time playing the movie:
Second time playing the movie:
I'm sure there's something wrong with my code, but I'm not able to figure out what exactly.. Any expert thoughts would be very much appreciated!
Cheers,
Harry