I just ran into a weird behaviour during my app-testing.
The app contains a videostream, played by a MPMoviePlayer
, where when entering fullscreen (via button on the players controller) on iOS6 the screen goes blank and the movie stopps playing. On iOS5 the movie continues as expected.
I believe this would be a a bug in iOS6, and are therefore wondering:
- Have anyone else experienced this behaviour?
- Is it a bug in my code, or in the OS?
- Any suggestions on how to deal with it?
On both phones the videostream plays as expected when the video is contained in a frame on screen (as a part of the view). However when entering fullscreen they differ. I have filmed the behaviour on both phones.
On a relatively new iPhone 4S (running iOS 5.1.1) the following (expected) behaviour: http://4340.no/ios5.mov
On an iPhone 3S (upgraded to iOS 6.0) the following (unexpected) behavour: http://4340.no/ios6.mov
The code handling the playButton:
-(IBAction) playButtonClicked:(id)sender
{
NSURL* url = [NSURL URLWithString:self.experiment.videoPath];
self.mpController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.mpController prepareToPlay];
self.mpController.view.frame = CGRectMake(0, 0, 320, 214);
[self.view addSubview:self.mpController.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mpController];
[self.mpController play];
}
Any tips or suggestions on how to solve this would be much appreciated.
Post Mortem - code and explanation:
Turns out viewWillDisapear
and viewDidDisappear
gets called when movie enters fullscreen on iOS6 (and not on iOS5).
The solution is to ensure that the MPMovieplayerController
is not running fullscreen
before dismissing the video player in either of these methods.
My new code then became:
(Note the && !self.mpController.fullscreen
-(void)viewDidDisappear:(BOOL)animated
{
if(self.mpController && !self.mpController.fullscreen){
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mpController];
[self.mpController.view removeFromSuperview];
self.mpController = nil;
}
}
if(self.mpController)
toif(self.mpController && !self.mpController.fullscreen)
before ditching the controller did fix this. I love when they change how stuf gets called :p – mariusnn