【问题标题】:How to programmatically control Play button in MPNowPlayingInfoCenter如何以编程方式控制 MPNowPlayingInfoCenter 中的播放按钮
【发布时间】:2020-05-29 08:16:52
【问题描述】:

在 Radio 应用程序中,为了暂停 AVPlayer,我们并没有真正暂停它,只是根据应用程序要求将其静音一段时间。 这里的问题是一切正常,但是当我将播放器静音时 MPNowPlayingInfoCenter 没有更新为暂停。有什么方法可以以编程方式控制 MPNowPlayingInfoCenter 控件?

尝试了所有可能的解决方案,例如设置 setActive(false) 但这会导致普通播放器出现问题。

这是解决方法

暂停时,我将其静音 120 秒,如果它仍处于该模式,我将暂停播放器,这是我正在使用的代码。

  self.player.rate = 0.0 // Automatically handles the MPNowPlayingInfoCenter Controls to Pause state
  self.player.isMuted = true
  secs = 120 

【问题讨论】:

  • // Automatically handles the MPNowPlayingInfoCenter Controls to Pause state. 请说明你如何更新 MPNowPlayingInfo,可能有问题。
  • 此外,如果您将一些日志输出添加到代码中以显示您的执行流程,这可能会有所帮助

标签: ios swift iphone avplayer mpnowplayinginfocenter


【解决方案1】:

要将 MPNowPlayingInfoCenter 设置为暂停,您可以将playbackRate 设置为0.0:

let nowPlayingInfo : [String: AnyObject] = 
    [MPNowPlayingInfoPropertyPlaybackRate: 0.0]

MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo

【讨论】:

  • @Sowji 如果这对您没有帮助并且您已经设置了rate = 0,请显示您当前用于暂停的代码
  • 感谢响应设置 PlaybackRate 没有任何区别。在静音频道时,我将播放器速率更改为 0.0,然后它自动更新了 MPNowPlayingInfoCenter 控件。
  • @Sowji 很高兴更新您的问题以显示您在暂停播放器时运行的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
相关资源
最近更新 更多