当没有互联网连接MPMoviePlayerViewController时,dismissModalViewController无法正常工作

时间:2011-12-16 09:51:43

标签: iphone objective-c ios modalviewcontroller

我有使用presentModalViewController:animated:调用的MPMoviePlayerViewController。当出现错误(没有互联网连接)时,我想解雇它。但是,dismissModalViewController似乎在这种情况下不起作用。

- (void)movieFinishedCallback:(NSNotification*)aNotification
{      
     NSLog(@"MOVIE FINISH CALL");

    // Obtain the reason why the movie playback finished
    NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];    
    // Dismiss the view controller ONLY when the reason is not "playback ended"

    if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded)
    {     

        NSlog(@"Check go here");
        MPMoviePlayerController *moviePlayer = [aNotification object];     
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:moviePlayer];        
        [self dismissModalViewControllerAnimated:YES];
    }
    else{
        [self dismissModalViewControllerAnimated:YES];        
    }
}



- (void)playPodcastRadio:(NSString *) urlRadio
{
     // Initialize the movie player view controller with a video URL string

    MPMoviePlayerViewController* mediaPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:urlRadio]];
    mediaPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown; 

    [[NSNotificationCenter defaultCenter] removeObserver:mediaPlayer name:MPMoviePlayerPlaybackDidFinishNotification object:mediaPlayer.moviePlayer];

    // Register this class as an observer instead    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification  object:mediaPlayer.moviePlayer];

    mediaPlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    // Present the movie player view controller    
    [self presentModalViewController:mediaPlayer animated:YES];

    [mediaPlayer.moviePlayer prepareToPlay];
    [mediaPlayer.moviePlayer play];
}

调用通知处理程序并到达Check go here日志。但它并没有消除modalViewController。 有人可以帮帮我吗?

谢谢

它发生在iOS 4.3和iOs 5

1 个答案:

答案 0 :(得分:1)

不确定您是否还在寻找答案。 根据Apple doc:http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerViewController_class/Reference/Reference.html#//apple_ref/occ/cl/MPMoviePlayerViewController

“要关闭模态显示的电影播放器​​视图控制器,请调用dismissMoviePlayerViewControllerAnimated方法。”