开发者

i have a problem with MPMoviePlayerController [iPhone SDK]

i want create an app with movie intro just like开发者_JAVA技巧 gameloft games . so when application has lunched , movie plays fine but before the move plays .. my FirstViewController xib file show first then movie start to play ! why ? here is my code :

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"movie" ofType:@"m4v"];

    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];

    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    IntroMovie.movieControlMode = MPMovieControlModeHidden;
    [IntroMovie play];
}


You need to wait for the movie to finish playing before adding your first view as a subview to window.

This should do the trick. Change your code to:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Hafez-2" ofType:@"mov"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];


    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [IntroMovie setOrientation:UIDeviceOrientationPortrait animated:NO];
    [IntroMovie play];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlaybackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil]; 
}

- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


An alternative is to add a different view (e.g. simple black background) and then replace it when the video has finished playing:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Hafez-2" ofType:@"mov"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];


    MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [IntroMovie setOrientation:UIDeviceOrientationPortrait animated:NO];
    [IntroMovie play];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlaybackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil]; 
    // Create an initial pure black view
    UIView* blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    blackView.backgroundColor = [UIColor blackColor];
    [window addSubview:blackView]; // sends [blackView retain]
    [blackView release];
    [window makeKeyAndVisible];
}

- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
    UIView* blackView = [[window subviews] objectAtIndex:0];
    [blackView removeFromSuperview]; // sends [blackView release]
    [window addSubview:viewController.view];
}

Let me know if you need modified source from your example and I can post it somewhere

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜