2009-10-18 66 views

回答

2

您可以簡單地創建一個帶有想要顯示的圖像的UIImageView(或標籤或任何其他),並將其添加到您的MoviePlayerControllerView。

​​

然後你就可以實例化的電影播放和註冊時收到通知LoadState的變化:

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

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

     [moviePlayer prepareToPlay]; 

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

然後在您的通知方法,執行邏輯給玩家添加到視圖:

- (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

這是創建應用程序的開場視頻播放時最光滑的效果。 – Shiny 2012-05-20 00:07:03

相關問題