2012-07-20 74 views
0

我想在游戏开始前使用MPMoviePlayerController来玩m4v文件。这场比赛是基于cocos2d游戏开始前的电影介绍

我做了MPMoviePlayerController与所需的文件,并将其作为子项添加到CCDirector(这是UIViewController的子类)。我之所以将MPMoviePlayerController作为孩子加入,是因为我希望游戏能够在后台继续加载。

我的问题是,我无法找到一种方法在视频结束后删除MPMoviePlayerController

请给出建议。

在此先感谢。

+0

不太熟悉这一点,但我的第一本能是,你能不能弹出包含电影播放器​​的视图,并且有菜单系统在后面,或者你想在介绍之后想要去的什么? – 2012-07-20 18:34:15

+0

流行?但我不推行导航控制器。我添加为CCDirector(它是viewcontroller上的子类)的子项,并将其删除我试图removefromParentView ....但不工作 – Anand 2012-07-20 18:38:42

回答

0

对于cocos2D游戏CCVideoPlayer类是最好的和容易播放视频。 CLICK HERE FOR EXTENSION

+0

雅我知道这...也许是最后的解决方案:)谢谢无论如何@raj建议 – Anand 2012-07-20 18:41:12

0

您应该可以听取MPMoviePlayerPlaybackDidFinishNotification通知,然后删除子视图。此代码在我的测试工作:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
self.player = moviePlayer; 

moviePlayer.controlStyle = MPMovieControlStyleNone; 
moviePlayer.shouldAutoplay = YES; 
[moviePlayer prepareToPlay]; 

moviePlayer.view.frame = self.view.bounds; 
moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
[self.view addSubview:moviePlayer.view]; 

[moviePlayer play]; 

// wait for the video to finish... 
MyViewController __weak *weakSelf = self; 
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:self.player queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 
    [[NSNotificationCenter defaultCenter] removeObserver:weakSelf name:MPMoviePlayerPlaybackDidFinishNotification object:weakSelf.player]; 

    // remove the view 
    [weakSelf.player.view removeFromSuperview]; 
}]; 

如果不工作,你可能需要张贴您的播放器创建和设置代码,让我们帮你弄清楚发生了什么事情。