CCVideoPlayer有延迟吗?
我使用CCVideoPlayer在我的游戏中播放视频,但在播放前有一点延迟,这会导致在播放前显示一个黑屏。是否有某种方法可以预加载视频或设置CCVideoPlayer,从而消除这种延迟。下面是我如何使用它的,启动时我有一个加载场景,当我的所有资源加载完毕后,我告诉它切换到主菜单,如下所示:CCVideoPlayer有延迟吗?,video,cocos2d-iphone,ccvideoplayer,Video,Cocos2d Iphone,Ccvideoplayer,我使用CCVideoPlayer在我的游戏中播放视频,但在播放前有一点延迟,这会导致在播放前显示一个黑屏。是否有某种方法可以预加载视频或设置CCVideoPlayer,从而消除这种延迟。下面是我如何使用它的,启动时我有一个加载场景,当我的所有资源加载完毕后,我告诉它切换到主菜单,如下所示: [[CCDirector sharedDirector] replaceScene:[MainMenu scene]]; 这就是我在主菜单中播放电影的方式: +(CCScene *) scene {
[[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
有什么不同的方法可以让视频立即开始播放,而不是在黑屏上稍有延迟吗?隐藏黑色闪烁的方法是在视频顶部显示第一帧的图像。半秒钟后(或无论黑色闪烁持续多长时间),隐藏第一帧以便视频显示。以下是一个例子:
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
,但是如果你不能在视频上方放置精灵,请尝试将视频的alpha设置为0,然后在调用块中将其设置为visible,以便在最初的半秒延迟(或任何需要的时间)后可以看到视频播放。这将导致视频在黑色闪烁过去后出现
如果需要添加切换视频播放器可见性的方法,请不要害怕修改视频播放器
在我的应用程序中,我启动一个mpmovieplayervewcontroller
,将其设置为不可见,然后在短暂延迟后将其设置为可见,以隐藏闪烁。在使用视频的cocos2d应用程序中,我使用[[[CCDirector sharedDirector]视图]添加子视图:…]添加电影播放器
所以我不会亲自使用CCVideoPlayer
,但它仍然适用于您
在github上查看
CCVideoPlayer
后,您应该能够在playmovieturl
中将其电影视图设置为不可见,并在上面的代码块示例中,将其设置为延时后可见。我希望这能有所帮助。延迟是正常的,uimovieplayercontroller有回调通知您何时准备就绪,但它们可能无法通过ccvideo实现……因此我如何避免延迟。因为这看起来不太好。搜索MPMoviePlayerLoadStateDidChangeNotification…此通知告诉您MPMoviePlayerServiceController何时准备播放视频,此时您将将其隐藏标志更改为“否”以显示该视频。虽然还有更多的例子,但我相信网络上有很多例子。或者将视频的第一屏作为图像添加到背景中,这样就不会出现黑屏:-)@learncos2d我似乎找不到一个适合我尝试做的例子。如果您能给我看一些代码,或者您知道我可以看的一个示例,我将非常感激!