我有使用presentModalViewController:animated:
調用的MPMoviePlayerViewController。當出現錯誤(無法連接互聯網)時,我想解僱它。但是,dismissModalViewController
在這種情況下似乎不起作用。當沒有互聯網連接時,dismissModalViewController不工作MPMoviePlayerViewController
- (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
我想你檢查,如果你的函數movieFinishedCallback:被稱爲萬一沒有互聯網連接?它被稱爲 – Niko
。它打印出支票去這裏。但電影播放器沒有被解僱:( –
不應該是[moviePlayer dismissModalViewControllerAnimated:YES];?(我不確定) – Niko