我正在开发一个带有MPMoviePlayerViewController实现的应用程序。有一个uitableview,其中包含视频链接,但问题是我的第一个视频播放效果很好,我从播放器中点击它然后我点击它播放的第二个视频但是当我点击完成它显示:"尝试关闭其视图当前不显示的模态视图控制器。"和屏幕黑色应用程序不会终止,但只是一个黑屏。我会告诉你我的代码。
.m文件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[[rssOutputData objectAtIndex:indexPath.row]xmlvideo]]];
[player.moviePlayer prepareToPlay];
[player.view setFrame: self.view.bounds];
[self presentMoviePlayerViewControllerAnimated:player];
[self.view addSubview: player.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[player.moviePlayer play];
}
- (void)MPMoviePlayerDidExitFullscreen:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[player.moviePlayer stop];
[player.moviePlayer.view removeFromSuperview];
}