我使用此代码来显示电影:
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
[self presentMoviePlayerViewControllerAnimated:mp]; [mp.moviePlayer play];
代码运行正常。但是,当应用程序在播放电影时进入后台时,当应用程序返回前台时,不会显示电影播放器。 (我看到调用presentMoviePlayerViewControllerAnimated:mp
在应用程序进入后台之前进入foregound是否有可能恢复正在播放的电影?
答案 0 :(得分:0)
您是否已将UIBackgroundmode设置为音频,并且在应用程序进入前景后播放视频时出现问题。请参阅此Tutorial on MPMoviePlayerViewController 此外,您可以尝试使用MPMoviePlayerViewController,它具有实现各种通知的选项。
答案 1 :(得分:0)
您可以实施通知技术来处理它。在电影播放器正在播放的类中添加通知,并将其与选择器关联。当应用程序转到后台然后在委托方法
- (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];
}
它解决了我的问题。