2009-10-18 7 views

Répondre

2

Vous pouvez simplement créer un UIImageView avec une image que vous souhaitez afficher (ou étiqueter ou autre chose) et l'ajouter à votre MoviePlayerControllerView.

UIImage *loadingScreenImage = [UIImage imageNamed:@"loadingScreen.png"]; 
loadingScreen = [[UIImageView alloc] initWithImage:loadingScreenImage]; // ivar & property are declared in the interface file 
[self.view addSubview:loadingScreen]; 
[loadingScreen release]; 

Ensuite, vous pouvez instancier le lecteur vidéo et vous inscrire pour recevoir une notification lorsque loadState change:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movie.trailerURL]; 

if ([moviePlayer respondsToSelector:@selector(loadState)]) { 

     [moviePlayer prepareToPlay]; 

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];} 

Ensuite, dans votre méthode de notification, faire la logique d'ajouter le joueur à la vue:

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{ 
    // Unless state is unknown, start playback 
    switch ([moviePlayer loadState]) { 
     case MPMovieLoadStateUnknown: 
      break; 
     case MPMovieLoadStatePlayable: 
      // Remove observer 
      [[NSNotificationCenter defaultCenter] 
      removeObserver:self 
      name:MPMoviePlayerLoadStateDidChangeNotification 
      object:nil]; 

      // Set frame of movie player 
      [moviePlayer.view setFrame:CGRectMake(0, 0, 480, 320)]; 
      [moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 
      [moviePlayer setFullscreen:YES animated:YES]; 
      [self.view addSubview:[moviePlayer view]]; 

      // Play the movie 
      [moviePlayer play]; 
         ... 
} 
+0

Il s'agit de l'effet le plus SMOOTH pour créer une vidéo d'ouverture d'une application. – Shiny

Questions connexes