MPMoviePlayerViewController的坑
坑一:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadState:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayerViewController.moviePlayer];
这里MPMoviePlayerPlaybackDidFinishNotification必须指定object:参数为moviePlayer即这个ViewController中的MPMoviePlayerController才可以发出来。而MPMoviePlayerLoadStateDidChangeNotification则不需要。
记得之前没这个坑,难道是iOS8之后出的问题?
坑二:
- (void)moviePlayerDidFinished:(NSNotification *)note { [self.moviePlayerViewController.moviePlayer stop]; }
上面是注册了MPMoviePlayerPlaybackDidFinishNotification通知。
在把MPMoviePlayerViewController present出来之后,载入的远程video。当用户点Done要关闭这个present时,需要stop moviePlayer来解决关闭之后仍然播放video的问题。但这还不够。。
仍然有机率会在dismiss之后还播放,貌似因为正在载入远程movie,还没有start,导致stop也无效。所以下面代码是解决办法,注册MPMoviePlayerLoadStateDidChangeNotification通知:
- (void)moviePlayerLoadState:(NSNotification *)note { //检查movie player是不是presenting if (self.moviePlayerViewController.presentingViewController==nil) { [self.moviePlayerViewController.moviePlayer stop]; } }












