Search code examples
iosmpmovieplayercontrolleruisplitviewcontroller

MPMoviePlayerController - Split view controller should have its children set before layout


What is the appropriate point to send the play message to a MPMoviePlayerController instance instantiated in a splitView detail View Controller?

My app is receiving the above console message (with a !) but not crashing...

The app is utilizing MPMoviePlayerController to play a movie from an asset URL and the responsilble method is called as follows:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self startPlayingVideo:self];
}

It plays the video just fine but the console message is looming... If I move the method call to viewWillAppear:animate:, the console message does not show up. The issue is now I can only hear audio and do not see the video.

For completeness, here is the called method...

- (void) startPlayingVideo:(id)sender

    NSURL *movieURL = [NSURL URLWithString:self.movieURLString];

    if (self.moviePlayer != nil){
       [self stopPlayingVideo:nil];
    }

    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL ];

    if (self.moviePlayer != nil){

        [[NSNotificationCenter defaultCenter] 
         addObserver:self
         selector:@selector(videoHasFinishedPlaying:)
         name:MPMoviePlayerPlaybackDidFinishNotification
         object:self.moviePlayer];

         self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

         [self.moviePlayer prepareToPlay];
         [self.moviePlayer play];

         [self.view addSubview:self.moviePlayer.view];
         [self.moviePlayer setFullscreen:YES animated:YES];

    } else {
         NSLog(@"Failed to instantiate the movie player.");
  }  
}

Solution

  • My original issue stemmed from having the MoviePlayerController as an entirely different viewController (embedded in a detail navigation controller). I redesigned the parent view to include a moviePlayer child view. This solved the issue.