开发者

How to have a menu when a movie is playing-iphone cocos2d

开发者 https://www.devze.com 2022-12-19 18:16 出处:网络
I play a movie using the following code NSString *path = [[NSBundle mainBundle] pathForResource:@\"cobra\" ofType:@\"mp4\"];

I play a movie using the following code

NSString *path = [[NSBundle mainBundle] pathForResource:@"cobra" ofType:@"mp4"];

theMovie=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
theMovie.scalingMode=MPMovieScalingModeAspectFill;
// Add an observer to catch when playback ends
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(transition:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
// Start playback
theMovie.movieControlMode = MPMovieControlModeDefault;
[theMovie play];

now i want to have a menu over the playing movie.I code like

MenuItemImage *item1 = [MenuItemImage itemFromNormalImage:@"Button_cobra.png" selectedImage:@"Button_cobra1.png" target:self selector:@selector (transition:)];
Menu *menu = [Menu menuWithItems:item1, nil];
menu.position = CGPointZero;
item1.position = ccp(330,260);
item1.scale = 0.5;
[self addChild:menu z:51];
NSLog(@开发者_开发知识库"Leaving Layer2");

But the menu is not getting displayed. Can anyone please tell me how to do it.


You have to wait until the window is loaded and then do something like this.

NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
    // Locate the movie player window
    UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
    // Add our overlay view to the movie player's subviews so it is 
    // displayed above it.
    PlayerOverlayView *overlay = [[PlayerOverlayView alloc]initForPlayerWithButtonDelegate:self];
    [moviePlayerWindow addSubview:overlay];
    [overlay release];
}

PlayerOverlayView is nothing special. Just a UIView subclass i made. I call this from the

- (void) moviePreloadDidFinish:(NSNotification*)notification

callback and it works great.

0

精彩评论

暂无评论...
验证码 换一张
取 消