【问题标题】:MPMoviePlayerViewController called from UITabBarController doesn't send notifications in IOS5从 UITabBarController 调用的 MPMoviePlayerViewController 不在 IOS5 中发送通知
【发布时间】:2012-01-03 11:02:45
【问题描述】:

我有一个应用程序在 IOS4 中运行良好,但在 IOS5 中停止显示视频。以前我使用的是 MPMoviePlayerController,所以我切换到 MPMoviePlayerViewController,现在视频在 IOS5 中显示正常。

但是,现在在 IOS5 中,当按下 Done 按钮时,视频会在 MPMoviePlayerViewController 中停止播放,但 MPMoviePlayerController 不再调用 Notifications。

层次结构如下:

AppDelegate -> UITabBarController -> UITableView -> UIViewController 在其中调用 MPMoviePlayerViewController。在 UIViewController 内部,代码如下所示:

MPMoviePlayerViewController *tmpMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
self.moviePlayer = tmpMoviePlayer;

[self presentMoviePlayerViewControllerAnimated:self.moviePlayer];

NSNotificationCenter *notificationCenter = [ NSNotificationCenter defaultCenter ];
[notificationCenter addObserver:self  
                       selector:@selector(moviePlayerPlaybackDidFinish:)  
                           name:MPMoviePlayerWillExitFullscreenNotification  
                         object:[self.moviePlayer moviePlayer ]]; 

我也尝试了以下通知名称,但没有一个被触发:

 MPMoviePlayerPlaybackDidFinishNotification 
 MPMoviePlayerPlaybackStateDidChangeNotification
 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
 MPMoviePlayerNowPlayingMovieDidChangeNotification
 MPMoviePlayerWillExitFullscreenNotification
 MPMoviePlayerDidExitFullscreenNotification

我看到了 SO posting,其中 MPMoviePlayerViewController 是从 UITabBarController 中调用的,并且调用 presentMoviePlayerViewControllerAnimated 的视图未正确选择,但我无法获得任何其他视图来调用 presentMoviePlayerViewControllerAnimated。

任何想法为什么在按下 MPMoviePlayerViewController 的完成按钮时不再调用通知?

【问题讨论】:

    标签: iphone notifications uitabbarcontroller ios5 mpmovieplayercontroller


    【解决方案1】:

    我确实解决了这个问题,但我不记得实际的修复是什么。但我可以展示现在有效的代码:

    [ notificationCenter addObserver: self 
                                selector:@selector(moviePlayerPlaybackDidFinish:) 
                                name: MPMoviePlayerPlaybackDidFinishNotification 
                                object: moviePlayer ];
    
    
    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    self.moviePlayer.shouldAutoplay = NO;  
    [self.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    [[self view] addSubview:[self.moviePlayer view]];   
    [self.moviePlayer setFullscreen:YES animated:YES];
    [self.moviePlayer play];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 2012-03-10
      • 2016-06-24
      • 2019-05-28
      相关资源
      最近更新 更多