0
votes

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;
    }
}
1
Are you doing anything in viewWillDisappear or viewDidDisappear that would cause the video to stop? That's what got me.rob5408
You are right. I am freeing the moviePlayer when the view do disapear.mariusnn
So updating my check from if(self.mpController) to if(self.mpController && !self.mpController.fullscreen) before ditching the controller did fix this. I love when they change how stuf gets called :pmariusnn
Upgraded my comment to an answer :)rob5408

1 Answers

1
votes

Make sure you're not stopping or releasing the video player in viewWillDisappear or viewDidDisappear.