我正在使用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
有什麼不同,我可以做的有聲視頻立即開始播放,而不是稍有延遲的黑屏?
延遲是正常的,uimovieplayercontroller有回調告訴你它什麼時候準備好了,但它們可能不會被ccvideo實現... – LearnCocos2D 2013-05-01 20:34:12
那麼我該如何解決延遲問題。因爲那看起來不太好。 – Stephen 2013-05-01 20:42:05
搜索MPMoviePlayerLoadStateDidChangeNotification ...此通知告訴您MPMoviePlayerViewController何時準備播放視頻,此時您將其隱藏標誌更改爲NO以顯示該視頻。還有更多,但我相信有幾個例子在網上浮動。 – LearnCocos2D 2013-05-02 00:48:12