Reputation: 361
I want to play a video with an MPMoviePlayerViewController. So in my view controller I register as an observer for MPMoviePlayerLoadStateDidChangeNotification
.
I then initialise the MPMoviePlayerViewController:
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]];
and wait for the notification to arrive. When it does I execute this code:
MPMoviePlayerController* playerController = notification.object;
if ([playerController loadState] & MPMovieLoadStatePlayable) {
if (self.mPlayerVC) {
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
}
}
Anyone an idea why this works for iOS 5 but not for iOS 6? Thanks
Upvotes: 1
Views: 3167
Reputation: 361
There seems to be a bug in iOS 6' MediaPlayer.framework. To get the video to play I call prepareToPlay
after initialising the MPMoviePlayerViewController
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]];
[self.mPlayerVC.moviePlayer prepareToPlay];
Now the notifications come in again but the app crashes when I call [self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
in the method that is called for the MPMoviePlayerLoadStateDidChangeNotification
.
To prevent the crash replace
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
with something like
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:self.mPlayerVC animated:YES completion:nil];
}
else if ([self respondsToSelector:@selector(presentModalViewController:animated:)]) {
[self presentModalViewController:self.mPlayerVC animated:YES];
}
Upvotes: 2