您应该能够收听MPMoviePlayerPlaybackDidFinishNotification
通知,然后删除子视图。这段代码在我的测试中有效:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.player = moviePlayer;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[moviePlayer prepareToPlay];
moviePlayer.view.frame = self.view.bounds;
moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
// wait for the video to finish...
MyViewController __weak *weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:self.player queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[[NSNotificationCenter defaultCenter] removeObserver:weakSelf name:MPMoviePlayerPlaybackDidFinishNotification object:weakSelf.player];
// remove the view
[weakSelf.player.view removeFromSuperview];
}];
如果这不起作用,您可能需要发布您的播放器创建和设置代码,以便我们帮助您弄清楚发生了什么。