2010-01-13 5 views
3

Je veux créer une application avec intro de films, tout comme les jeux gameloft. donc quand l'application a déjeuné, le film joue bien mais avant que le mouvement joue .. mon dossier de xib de FirstViewController montrent d'abord alors le film commence à jouer! Pourquoi ? voici mon code:J'ai un problème avec MPMoviePlayerController [iPhone SDK]

- (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]; 
} 
+3

Quelle a été votre application pour le déjeuner? :) –

Répondre

3

Une alternative est d'ajouter une vue différente (par exemple simple fond noir), puis le remplacer lorsque la vidéo a fini de jouer:

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

Laissez-moi savoir si vous avez besoin source modifiée de votre exemple et je peux l'afficher quelque part

+0

: O: O: O: O Je vraiment fatigué d'essayer des types de codes de 1000000! ne change toujours pas pourquoi pourquoi pourquoi pourquoi? pouvez-vous créer un exemple de projet de votre code? Je ne sais pas ce que je peux faire! – Momi

+1

J'ai ajouté ma version modifiée de la source originale que vous avez posté ici http://www.filefactory.com/file/a2fbd87/n/MoviePlayer.zip – cidered

6

Vous devez attendre que le film fini de jouer avant d'ajouter votre première vue comme une sous-vue à la fenêtre.

Cela devrait faire l'affaire. Changer votre code:

- (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]; 
} 
+0

ne change pas !!!!!!!!!!!!!!!!!!!!!!!! – Momi

+1

Juste pour clarifier, vous voulez que la vidéo joue AVANT que votre première vue s'affiche? J'ai téléchargé votre source (à partir de la réponse que vous avez maintenant supprimée) et cela fonctionne effectivement donc vous avez fait quelque chose de mal! Etes-vous sûr que vous avez déplacé ces lignes en commençant par [window ... OUT OF applicationDidFinishLaunching: et dans moviePlaybackDidFinish: ??? – cidered

+0

ouais je suis sûr !!! mais je ne comprends pas pourquoi ça ne marche pas !!! le message n'a pas supprimé – Momi

Questions connexes