2012-11-20 73 views

回答

1

//這是你給視頻的路徑並初始化它的地方。

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video_file_name" ofType:@"mp4/mov"]]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
moviePlayer.controlStyle = MPMovieControlStyleNone; 
moviePlayer.shouldAutoplay = YES; 
NSLog(@"%f", [[CCDirector sharedDirector] view].frame.size.width); 
moviePlayer.view.frame = [[CCDirector sharedDirector] view].frame; 
[[[CCDirector sharedDirector] view] addSubview:moviePlayer.view]; 
[[[CCDirector sharedDirector] view] bringSubviewToFront:moviePlayer.view]; 
[moviePlayer play]; 



[[NSNotificationCenter defaultCenter] addObserver:self // the object listening/"observing" to the notification 
selector:@selector(playbackComplete:) // method to call when the notification was pushed 
name:MPMoviePlayerPlaybackDidFinishNotification // notification the observer should listen to 
object:moviePlayer]; // the object that is passed to the method 

//[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene] withColor:ccWHITE]]; 

} 

//這是你定義會發生什麼,一旦播放完成

-(void)playbackComplete:(id)sender { 
// [(MPMoviePlayerController *)sender stop]; 
// ((MPMoviePlayerController *)sender).view.hidden=YES; 

// [((MPMoviePlayerController *)sender) removeFromParentAndCleanup:YES]; 
[moviePlayer.view removeFromSuperview]; 

//這是你加載其他場景(例如:圖片,動畫等)

NSLog(@"Make transition"); 
CGSize size = [[CCDirector sharedDirector] winSize]; 
[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.0 scene:[GameLayer scene] ]]; 

} 
相關問題