NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"clip" ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0, 0,320, 460);
[viewController.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer setShouldAutoplay:YES];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayer setMovieControlMode:MPMovieControlModeHidden];
我正在播放mp4文件我需要在电影结束时删除.FromSuperview ....在通知中。可能吗。
答案 0 :(得分:0)
是的,这是可能的。您需要将Observers添加到MPMoviePlayer发送的通知中(可能在您的viewDidLoad中):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(exitedFullscreen)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishedPlayback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
然后在通知触发时调用的方法中:
- (void)finishedPlayback:(NSNotification *)notification
{
[self.moviePlayer setFullscreen:NO animated:YES];
}
-(void)exitedFullscreen
{
[self.moviePlayer.view removeFromSuperView];
}