4

MPMoviePlayerViewController に問題があります。コントローラーが指定された URL でムービーを見つけられない場合、白い画面が表示され、閉じることができません。

これは、ムービープレーヤーを開始する方法です。

- (void) playVideo:(NSString*)path 
{
 NSURL* url = [NSURL URLWithString:path];

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

 double osversion = [[[UIDevice currentDevice] systemVersion] doubleValue];
 if (osversion >= 3.2) 
 {
  mplayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

  if (mplayerVC)
  {
   mplayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
   [mplayerVC.moviePlayer play];
   mplayerVC.moviePlayer.shouldAutoplay = TRUE;

  [self presentMoviePlayerViewControllerAnimated:mplayerVC];

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

 }  
}

そして、これが moviePlayBackDidFinish: メソッドがこのように見える方法です


    - (void) moviePlayBackDidFinish:(NSNotification*)notification 
    {
     [[NSNotificationCenter  defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];  

     NSError* error = [[notification userInfo] valueForKey:@"error"];
     if (error != nil)
     {
      // Movie ended with an error
      DLog(@"error=%@", error);
     }
     else 
     {
      // Movie ended successfully
     }

     [self dismissMoviePlayerViewControllerAnimated];
     SAFE_DEL(mplayerVC);
    }

白い画面が表示されるのは、URL が間違っている場合のみです

4

1 に答える 1

3

みんな気にしないで、私はそれを理解しました。

どうやらmoviePlaybackDidFinishメソッドで呼び出す必要があります

[player stop];

コントローラーを閉じる前に。

上記の player は、次のように取得された MPMoviePlayerController オブジェクトです。

MPMoviePlayerController *player = [notification object];
于 2010-10-25T21:23:15.343 に答える