CCVideoPlayer有延迟吗?

问题描述:

我正在使用CCVideoPlayer在我的游戏中播放视频,但在播放之前它有一个轻微的延迟,导致黑屏在播放之前显示。是否有某种方式可以预先加载视频或以避免延迟的方式设置CCVideoPlayer。这里是我如何使用它,我有一个加载场景在启动时,当我所有的资源加载我告诉它切换到主菜单,如下所示:CCVideoPlayer有延迟吗?

[[CCDirector sharedDirector] replaceScene:[MainMenu scene]]; 

然后这是我在玩电影在主菜单:

+(CCScene *) scene 
{ 
    CCScene *scene = [CCScene node]; 
    MainMenu *layer = [MainMenu node]; 
    [scene addChild: layer]; 

    return scene; 
} 

- (id) init { 

    if((self=[super init])) { 

       [CCVideoPlayer setDelegate: self]; 

    } 

    return self; 
} 

- (void)onEnter{ 

     [self playVideo]; 
    } 

    [super onEnter]; 
} 

-(void)onExit{ 

    [super onExit]; 
} 

- (void) playVideo { 

    [CCVideoPlayer playMovieWithFile: @"MenuBuild.m4v"]; 
} 

- (void) movieStartsPlaying { 

    [[CCDirector sharedDirector] stopAnimation]; 

} 

- (void) moviePlaybackFinished 
{ 

    [[CCDirector sharedDirector] startAnimation]; 

} 

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 
// Updates orientation of CCVideoPlayer. Called from SharedSources/RootViewController.m 
- (void) updateOrientationWithOrientation: (UIDeviceOrientation) newOrientation 
{ 
    [CCVideoPlayer updateOrientationWithOrientation:newOrientation ]; 
} 
#endif 

- (void) dealloc { 

    [CCVideoPlayer setDelegate: nil]; 

    [super dealloc]; 
} 
@end 

有什么不同,我可以做的有声视频立即开始播放,而不是稍有延迟的黑屏?

+0

延迟是正常的,uimovieplayercontroller有回调告诉你它什么时候准备好了,但它们可能不会被ccvideo实现... – LearnCocos2D 2013-05-01 20:34:12

+0

那么我该如何解决延迟问题。因为那看起来不太好。 – Stephen 2013-05-01 20:42:05

+0

搜索MPMoviePlayerLoadStateDidChangeNotification ...此通知告诉您MPMoviePlayerViewController何时准备播放视频,此时您将其隐藏标志更改为NO以显示该视频。还有更多,但我相信有几个例子在网上浮动。 – LearnCocos2D 2013-05-02 00:48:12

隐藏黑色闪烁的方法是在视频顶部显示第一帧的图像。半秒后(或者黑色闪烁持续很长时间)隐藏第一帧,以便视频显示。这里有一个例子:

CCSprite* first_frame = [CCSprite spriteWithFile:@"first_frame.png"]; 
[self addChild:first_frame]; 

id delay_action = [CCDelayTime actionWithDuration:0.5f]; 

id call_action = [CCCallBlock actionWithBlock:^ 
{ 
    first_frame.visible = FALSE; 
}]; 

[first_frame runAction:[CCSequence actions:delay_action, call_action, nil]]; 

我没有使用过CCVideoPlayer,但如果你不能把一个精灵在在视频之上,尝试设置视频的阿尔法是最初为0,然后在呼叫块将其设置为可见,以便在最初的半秒延迟(或需要的任何时间量)之后可以看到视频正在播放。这会导致视频在黑色闪烁通过后出现。

如果您需要添加切换其可见性的方式,请不要害怕修改视频播放器。

在我的应用程序中,我开始将MPMoviePlayerViewController关闭为不可见,然后在短暂延迟后将其设置为可见,以隐藏该闪烁。在我使用视频的cocos2d应用程序中,我使用[[[CCDirector sharedDirector] view] addSubview:...];添加了电影播放器​​,因此我个人不使用CCVideoPlayer,但它仍然适用于您。

在github上查看CCVideoPlayer之后,您应该能够将其电影视图设置为在playMovieAtURL和上面的代码块示例中不可见,并在延迟时间后将其设置为可见。我希望这有帮助。