Reputation: 112
I have created a View which plays video using MPMoviePlayerController. Now I wish to show a CCLayer over/overlapping this View while the video is in action. How to move forward with this?
Upvotes: 1
Views: 303
Reputation: 112
//This is where you give path of your video and init it.
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]];
}
//This is where you define what happens once the playback is complete
-(void)playbackComplete:(id)sender {
// [(MPMoviePlayerController *)sender stop];
// ((MPMoviePlayerController *)sender).view.hidden=YES;
// [((MPMoviePlayerController *)sender) removeFromParentAndCleanup:YES];
[moviePlayer.view removeFromSuperview];
//This is where you load another scene(Ex: Image, Animation etc)
NSLog(@"Make transition");
CGSize size = [[CCDirector sharedDirector] winSize];
[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.0 scene:[GameLayer scene] ]];
}
Upvotes: 1