我正在使用以下代码在 MPMoviePlayerController 中播放视频文件
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"one" ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:filePath];
_movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
[_movie.view setFrame:self.view.bounds];
[self.view addSubview:_movie.view];
_movie.fullscreen=YES;
_movie.controlStyle=MPMovieControlStyleFullscreen;
[_movie prepareToPlay];
[_movie play];
和
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(close:)name:MPMoviePlayerPlaybackDidFinishNotification object:_movie];
和
- (void) close:(NSNotification *)notification {
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if(reason == MPMoviePlaybackStateStopped) {
NSLog(@"Stop");
}
else if (reason == MPMovieFinishReasonPlaybackEnded) {
NSLog(@"Playback Ended ");
}
else if (reason == MPMovieFinishReasonUserExited) {
NSLog(@"Exited");
[_movie.view removeFromSuperview];
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
NSLog(@"Error");
}
}
我能够得到 Notification ,并且 Movieplayer 没有从超级视图中删除。
可能是什么问题呢 ??