【问题标题】:How to start the video in iPad from where it was stopped earlier?如何在 iPad 中从之前停止的位置开始播放视频?
【发布时间】:2013-01-28 06:54:27
【问题描述】:

我正在 iPad 上播放视频,然后使用 iPad 上的“主页”按钮停止播放。当我再次开始播放视频时,它应该从之前停止的地方开始,而不是从头开始。谁能告诉我该怎么做?

要从头开始播放视频,我使用了

- (void)applicationWillEnterForeground:(UIApplication *)application
    {
       NSLog(@"app enter foreground");
       PlayVideo *PVC=[[PlayVideo alloc] initWithNibName:@"PlayVideo" bundle:nil];
       self.window.rootViewController=PVC;     
    }

【问题讨论】:

  • 您是否覆盖主页按钮操作?这可能会导致您的应用被拒绝。
  • 不,我正在重写“AppDelegate”方法,以重新启动应用程序。但我希望它从它停止的地方开始。
  • 当您将应用程序置于后台时,只需暂停视频并在您回来时再次播放。

标签: iphone ios objective-c ipad xcode4.3


【解决方案1】:

使用此方法监听 videoplayer 的状态变化。

[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(playbackStateChanged) 
name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

在 applicationDidEnterBackground 中,捕获播放时间。 MPMoviePlayerController 符合 MPMediaPlayback 协议,并且有一个可用的 currentPlaybackTime 属性。 将此播放保存在 NSUserDefaults 或任何您觉得容易的地方,以便下次启动应用程序,即在 applicationDidiEnterForeground 方法中从该播放时间恢复播放。

【讨论】:

  • @Ankita:你有没有得到结果。如果有,请接受答案。
  • 我使用 applicationWillEnterForeground 委托方法来解决问题。因此我没有尝试您建议的方法,我会尝试让您知道。Thnks
猜你喜欢
  • 1970-01-01
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多