سؤال

لدي مشكلة في 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];    
  }

 }  
}

وهذه هي الطريقة


    - (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 يشير إلى خطأ

هل كانت مفيدة؟

المحلول

لا تهتم يا رفاق ، لقد اكتشفت ذلك.

على ما يبدو في طريقة moviePlaybackDidfinish عليك الاتصال

[player stop];

قبل رفض وحدة التحكم.

أعلاه ، اللاعب هو كائن mpmoviePlayerController الذي تم الحصول عليه مثل هذا:

MPMoviePlayerController *player = [notification object];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top