tags:

views:

1246

answers:

2

i want create an app with movie intro just like 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];
}
+5  A: 

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];
}
cidered
doesn't any change !!!!!!!!!!!!!!!!!!!!!!!!!!!
Momeks
Just to clarify, you want the video to play BEFORE your first view displays? I downloaded your source (from the answer you have now deleted) and this does indeed work so you have done something wrong! Are you sure you moved those lines beginning [window ... OUT OF applicationDidFinishLaunching: and into moviePlaybackDidFinish: ???
cidered
yeah iam sure !!! but i don't understand why doesn't work !!! the post has undeleted
Momeks
I posted another answer with a slightly different approach. Try that. I hope it helps you.
cidered
+2  A: 

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

cidered
:O:O:O:Oi really tired of trying 1000000 types of codes ! still doesn't change why why why why why ?can you create a sample project of your code? i dont know what can i do !
Momeks
I added my modified version of the original source you posted here http://www.filefactory.com/file/a2fbd87/n/MoviePlayer.zip
cidered