Question

I'm having a problem with MPMoviePlayerController on iOS sometimes playing a video (loaded from a local file) and sometimes just failing silently. The same video launched at the beginning of the app just the same way every time. When it fails, it doesn't notify in any way, I just see a black screen.

Here's the code I'm using to play the video (this is a cocos2d-x based game and I attach the movie player controller as a child of the EAGLView):

- (void)playVideo:(NSString*)filePath
{
    NSURL* url = [NSURL fileURLWithPath:filePath];
    _moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];

    EAGLView* view = [EAGLView sharedEGLView];

    _moviePlayerController.view.frame = view.bounds;
    _moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
    _moviePlayerController.fullscreen = YES;
    _moviePlayerController.controlStyle = MPMovieControlStyleNone;
    _moviePlayerController.shouldAutoplay = NO;

    [view addSubview:_moviePlayerController.view];

    [_moviePlayerController prepareToPlay];
}

- (void)videoFinished:(NSNotification*)notification
{
    [_moviePlayerController.view removeFromSuperview];
    [_moviePlayerController release];
}

- (void)videoLoadStateChanged:(NSNotification*)notification
{
    if ((_moviePlayerController.loadState & MPMovieLoadStatePlayable) != 0)
    {
        [_moviePlayerController play];
    }
}

When the playback fails, I get the following notifications:

  • MPMoviePlayerNowPlayingMovieDidChangeNotification
  • MPMovieSourceTypeAvailableNotification

And nothing else. When the playback works, I get these:

  • MPMoviePlayerNowPlayingMovieDidChangeNotification
  • MPMovieSourceTypeAvailableNotification (up to here, same as when it fails)
  • MPMovieMediaTypesAvailableNotification
  • MPMovieMediaTypesAvailableNotification
  • MPMovieDurationAvailableNotification
  • MPMoviePlayerLoadStateDidChangeNotification
  • MPMoviePlayerLoadStateDidChangeNotification
  • MPMoviePlayerPlaybackStateDidChangeNotification
  • MPMovieNaturalSizeAvailableNotification
  • MPMoviePlayerReadyForDisplayDidChangeNotification
  • MPMoviePlayerPlaybackStateDidChangeNotification
  • MPMoviePlayerPlaybackDidFinishNotification

I've tried several different alternatives, including using a MPMoviePlayerViewController, but every time I get the same weird behavior. Any ideas?

Was it helpful?

Solution

My problem ended up being totally unrelated to the symptoms...

It appears to be some sort of bug with Crittercism running on iOS 7. While looking into a debug message in our console ("(webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds") we came across this question: iOS 7 UIWebView not rendering, which suggests installing an updated version of Crittercism. After doing that, our problem with video playback seems to be fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top