我的标题可能表达得不够清楚,更准确地说,我的NSNotification在影片播放完毕后没有将其视图消失。我发现其他人也有这个问题,但没有解决方案,似乎可能是我正在运行的iOS 6的问题。
当视频播放完毕后,需要按“完成”按钮才能让它消失,但我希望它能自动消失,因为我会在解决这个问题后使用MPMovieControlStyleNone。这是我剥离未使用部分后的代码:
#import "MovieViewController.h"
@interface MovieViewController ()
@end
@implementation MovieViewController
@synthesize moviePlayer = _moviePlayer;
- (IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"TestMovie" ofType:@"mov"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
@end`