如何在播放电影时出现菜单-iphone cocos2d

发布于 2024-08-20 19:59:47 字数 1029 浏览 2 评论 0原文

我使用以下代码播放电影

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];

现在我想在播放的电影上有一个菜单。我的代码如下

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");

但菜单没有显示。 谁能告诉我该怎么做。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里南柯 2024-08-27 19:59:47

您必须等到窗口加载完毕,然后执行类似的操作。

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 没什么特别的。只是我制作的 UIView 子类。我从

- (void) moviePreloadDidFinish:(NSNotification*)notification

回调中调用它,效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文