views:

474

answers:

1

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.

+2  A: 

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. Here is a screen shot.

image

Joe Cannatti