我创建了一个使用 MPMoviePlayerController 播放视频的视图。现在我希望在视频播放时显示一个 CCLayer 覆盖/重叠此视图。如何继续前进?
问问题
297 次
1 回答
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] ]];
}
于 2013-03-12T16:16:18.840 回答