How to resume a movie that#39;s being played with presentMoviePlayerViewControllerAnimated(如何恢复正在使用 presentMoviePlayerViewControllerAnimated 播放的电影)
问题描述
我正在使用此代码来显示电影:
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 播放的电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何恢复正在使用 presentMoviePlayerViewControllerAnim
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
