MPMoviePlayerController随机不播放电影

时间:2014-01-24 15:59:12

标签: ios cocos2d-iphone mpmovieplayercontroller

我在iOS上遇到MPMoviePlayerController的问题,有时会播放视频(从本地文件加载),有时只是默默地失败。每次都以相同的方式在应用开始时启动相同的视频。当它失败时,它不会以任何方式通知,我只是看到黑屏。

这是我用来播放视频的代码(这是一个基于cocos2d-x的游戏,我将电影播放器​​控制器作为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];
    }
}

当播放失败时,我收到以下通知:

  • MPMoviePlayerNowPlayingMovieDidChangeNotification
  • MPMovieSourceTypeAvailableNotification

没有别的。当播放工作时,我得到这些:

  • MPMoviePlayerNowPlayingMovieDidChangeNotification
  • MPMovieSourceTypeAvailableNotification(到此为止,与失败时相同)
  • MPMovieMediaTypesAvailableNotification
  • MPMovieMediaTypesAvailableNotification
  • MPMovieDurationAvailableNotification
  • MPMoviePlayerLoadStateDidChangeNotification
  • MPMoviePlayerLoadStateDidChangeNotification
  • MPMoviePlayerPlaybackStateDidChangeNotification
  • MPMovieNaturalSizeAvailableNotification
  • MPMoviePlayerReadyForDisplayDidChangeNotification
  • MPMoviePlayerPlaybackStateDidChangeNotification
  • MPMoviePlayerPlaybackDidFinishNotification

我尝试了几种不同的选择,包括使用MPMoviePlayerViewController,但每次我都得到同样奇怪的行为。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我的问题最终与症状完全无关......

似乎是在iOS 7上运行Crittercism的某种错误。在我们的控制台("(webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds")中查看调试消息时,我们遇到了这个问题:iOS 7 UIWebView not rendering,建议安装一个更新版的Crittercism。在这之后,我们的视频播放问题似乎已得到解决。