您可以实施通知技术来处理它。在正在播放电影播放器的类中添加一个通知,并将其关联一个选择器。当应用程序进入后台然后在委托方法中
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask = 0;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
}
编写此代码。实际上,当应用程序进入后台时,它会暂停 MPMoviePlayerController,因此当它进入前台时,您会发布通知,该通知调用实现电影控制器的类中的方法并在此方法中再次播放。
-(void)playIntroAnimationAgain
{
[[NSNotificationCenter defaultCenter]removeObserver:self name:NOTIFICATION_PlayAgain_Player object:nil];
[self.moviePlayerController play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playIntroAnimationAgain)name:NOTIFICATION_PlayAgain_Player object:nil];
}
它解决了我的问题。