我正在使用此代码来显示电影:
I'm uisng this code to display a movie:
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
[self presentMoviePlayerViewControllerAnimated:mp]; [mp.moviePlayer play];
代码运行良好.但是,当应用程序在播放电影时进入后台时,当应用程序返回前台时,不会显示电影播放器.(我看到了调用 presentMoviePlayerViewControllerAnimated:mp
The code is working fine. However when the application goes to the background while playing a movie, when the app comes back in the foreground the movieplayer is not displayed. (I see the view of the controller that called presentMoviePlayerViewControllerAnimated:mp
是否可以在进入前台时恢复应用进入后台之前正在播放的电影?
Is it possible when entering the foregound to resume the movie that was playing before the app went to the background?
你可以实现通知技术来处理它.在正在播放电影播放器的类中添加一个通知,并将其关联一个选择器.当应用程序进入后台时,然后在委托方法中
you can implement notification techniques to handle it. Add a notification in the class where movie player is playing and associate with it a selector. When app goes to background then in the delegate method
- (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,因此当它进入前台时,您会发布通知,该通知调用实现电影控制器的类中的方法并在此方法中再次播放.
write this code.Actually when app goes background it pauses the MPMoviePlayerController so when it is coming to foreground you post the notification which call the method in class where movie controller is implemented and play it again in this method.
-(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];
}
它解决了我的问题.
这篇关于如何恢复正在使用 presentMoviePlayerViewControllerAnimated 播放的电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!