首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >cocos2d:在菜单背景下播放视频

cocos2d:在菜单背景下播放视频
EN

Stack Overflow用户
提问于 2010-12-16 04:52:45
回答 1查看 10.6K关注 0票数 17

我有一个CCLayer与我的应用程序的开始菜单,我想有一个简短的电影在背景中播放。我已经成功地在glView中播放了一部电影,但当它播放时,菜单并没有显示出来。为了处理电影,我实例化了一个MPMoviePlayerController,然后以这种方式将其视图添加到glView中:

代码语言:javascript
复制
[[[CCDirector sharedDirector] openGLView] addSubview:moviePlayer.view];

我看过这个问题很相似

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

但我想知道是否有更好的解决方案,可能会让我仍然利用cocos2d框架实体(而不是我自己的观点)。

我试着用这种方式把moviePlayer.view发回去

代码语言:javascript
复制
[theView sendSubviewToBack:moviePlayer.view];

但是菜单仍然被电影隐藏了..。

(许多小时后..)

好的,正如您在第一条评论中所看到的,我已经意识到(可能)唯一的方法就是利用自定义视图。我这样做了,它在模拟器中运行,方法是在moviePlayer.view之后向glView添加任何视图。然而,当我用3.1.3 FW在我的目标IPod touch上运行它时,电影视图总是在顶部。因此,我意识到MPMoviePlayerController实际上创建了自己的窗口和视图。一些帖子(如这篇Overlay on top of Streaming MPMoviePlayerController)建议拦截加载新窗口的事件,然后才添加子视图。

这就是我试图做的,但实际上无论是在模拟器上还是在目标Ipod上,都没有捕捉到这个事件。因此,我添加了一个预定的选择器-(void)更新,它是这样实现的:

代码语言:javascript
复制
-(void) update{
    NSArray *windows = [[UIApplication sharedApplication] windows];
    if ([windows count] > 1)
    {
    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
    UIView *theView = [[CCDirector sharedDirector] openGLView];
    [logo setCenter:ccp(240,80)];
    [moviePlayer.view addSubview:logo];
        [self unscheduleAllSelectors];
    }
}

但这部电影仍然位居榜首。

请各位帮帮忙,不胜感激!

(几天后……)我还等待了2秒钟,当电影实际运行时,添加我的徽标视图作为电影播放器的子视图。它在模拟器上工作正常,但在Ipod (3.1.3)上却得到了不同的结果。第一次播放电影时,不会显示徽标(电影在顶部)。然而,因为一旦电影结束,播放方法就会被收集起来,从第二次以电影为背景来描述徽标开始(我会这样做)。你觉得这有什么意义吗?

我真的需要了解如何解决这个问题,这是相当荒谬的,我已经成功地在两个月内开发了一款游戏,现在我被困在开始菜单的两周:)

无论如何,如果我已经决定粘贴我正在尝试修复的层的整个代码,这样您就可以更好地找出问题所在(或者至少这是我的希望:)

代码语言:javascript
复制
+(id) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];

    // 'layer' is an autorelease object.
    StartMenu *layer = [StartMenu node];

    // add layer as a child to scene
    [scene addChild: layer];

    // return the scene
    return scene;
}

-(void) update{
    timer ++;
    if (timer==120){

    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stupidLogo.png"]];
    UIView *theView = [[CCDirector sharedDirector] openGLView];
    [logo setCenter:ccp(240,80)];
    //logo.transform = CGAffineTransformMakeRotation(3.14/2);
    [moviePlayer.view addSubview:logo];
        [self unscheduleAllSelectors];
    }
}
-(id) init{
    self = [super init];

    [self schedule: @selector(update)];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test_005_conv_06.mp4" ofType:@""]];        
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    // Register to receive a notification when the movie has finished playing.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];

    if ([moviePlayer respondsToSelector:@selector(view)]) {
        if([MPMoviePlayerController instancesRespondToSelector:@selector(view)]){
        // Use the new 3.2 style API
        moviePlayer.controlStyle = MPMovieControlStyleNone;
        moviePlayer.shouldAutoplay = FALSE;
        // This does blows up in cocos2d, so we'll resize manually
        // [moviePlayer setFullscreen:YES animated:YES];
        [moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];
        CGSize winSize = [[CCDirector sharedDirector] winSize];

        moviePlayer.view.frame = CGRectMake(0, 0, winSize.height, winSize.width);   // width and height are swapped after rotation
        [[[CCDirector sharedDirector] openGLView] addSubview:moviePlayer.view];
        [moviePlayer play];
        }
    } else {
        // Use the old 2.0 style API
        moviePlayer.movieControlMode = MPMovieControlModeHidden;
        [moviePlayer play];
    }
    return self;
}


- (void)moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerController *moviePlayer = [notification object];
    [moviePlayer play];
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4454758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档