这是我的代码
- (void)viewDidLoad
{
...
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:_moviePlayerController.view];
_moviePlayerController.fullscreen = YES;
_moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
_moviePlayerController.controlStyle=MPMovieControlStyleDefault;
[_moviePlayerController play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieIsOver:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
- (void)movieIsOver:(NSNotification *)notification
{
NSLog(@"movie is over");
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.moviePlayerController.view removeFromSuperview];//moviePlayerController is MPMoviePlayerController
}
当电影播放结束时,我看不到“电影结束”日志,并且不删除moviePlayerController.view。我不知道为什么。
修改 MPMoviePlayerPlaybackDidFinishNotification运行良好。我看到“电影结束”日志。问题是moviePlayerController.view未被删除。
答案 0 :(得分:1)
我找到了解决方案:添加
_moviePlayerController.fullscreen = NO;
从superview中删除视图之前
答案 1 :(得分:0)
而不是将_moviePlayerController.view添加为子视图
[self.view addSubview:_moviePlayerController.view];
你可以像这样出现_moviePlayerController:
[self presentMoviePlayerViewControllerAnimated: _moviePlayerController];
并且在movieIsOver方法中你只需忽略
[self dismissMoviePlayerViewControllerAnimated];
我希望得到它的帮助