MPMoviePlayerController 在后台 iOS 中运行



在视频开始播放并触摸结束之前,视图控制器更改,视频开始在后台的不同视图控制器中播放。如何解决此问题?我想要的是,如果视图控制器发生变化,则停止播放。

- (void)viewDidLoad
{
    [super viewDidLoad];

 movpath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"m4v"];
    mpviewController = [[MPMoviePlayerViewController alloc]
                        initWithContentURL:[NSURL fileURLWithPath:movpath]];
    MPMoviePlayerController *mp = [mpviewController moviePlayer];
    [mp prepareToPlay];
    [mp setFullscreen:YES animated:YES];
    mp.controlStyle = MPMovieControlStyleNone;
    [[mpviewController moviePlayer] play];
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
    [self performSegueWithIdentifier:@"mainView" sender:self];
    [[mpviewController moviePlayer] stop];
    [mpviewController.view removeFromSuperview];
}

您可以在 -(void)viewDidDisappear 方法中停止您的 moviePlayer

最新更新