ios - 如何在控制中心更新播放位置?

标签 ios swift control-center

这是我从命令中心观察变化的方式:

    commandCenter.playCommand.addTarget(self, action: #selector(play))
    commandCenter.pauseCommand.addTarget(self, action: #selector(pause))
    commandCenter.changePlaybackPositionCommand.addTarget { event in
        let seconds = (event as? MPChangePlaybackPositionCommandEvent)?.positionTime ?? 0
        let time = CMTime(seconds: seconds, preferredTimescale: 1)
        self.player.seek(to: time)
        return .success
    }

当我改变 slider 的位置时,我的应用程序收到回调并且音频的位置被更新,但是......控制中心中 slider 的位置恢复到以前的状态。为什么?

问题是:

为什么它不停留在我离开手指的位置,而不是回到之前的位置?

最佳答案

您必须设置 nowPlayingInfo 的 MPNowPlayingInfoPropertyPlaybackRate、MPMediaItemPropertyPlaybackDuration 和 MPNowPlayingInfoPropertyElapsedPlaybackTime。您想在每次播放/暂停/跳过时更新 nowPlayingInfo。

关于ios - 如何在控制中心更新播放位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55100507/

相关文章:

ios - 以编程方式显示控制中心 ios

后台模式下的IOS应用

ios - 当应用程序失去焦点时,基于 BLE 值的 Swift 通知

Swift Vapor Fluent 更新现有行

ios - Swift iOS 将字符串 "Hello"屏蔽为 "Hxxxo"

ios - 无法在模拟器上打开 iPhone 控制中心

ios6 - numberOfRowsInSection 不为自定义 tableviewcell、委托(delegate)/数据源集运行

ios - 使用 Storyboard更改 UItabbar 项目的图像

ios - 使 UIViewPropertyAnimator 永不完成

ios - 如何实现从ControlCenter中查找?