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

4
这是我从命令中心观察变化的方式:
    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
    }

当我改变滑块的位置时,我的应用程序会接收回调并更新音频位置,但是……控制中心中的滑块位置会回到先前的状态。为什么?
问题是:
为什么它不能停留在我离开手指的位置,而是回到以前的位置?
1个回答

7

您需要设置nowPlayingInfo的MPNowPlayingInfoPropertyPlaybackRate、MPMediaItemPropertyPlaybackDuration和MPNowPlayingInfoPropertyElapsedPlaybackTime属性。每次播放/暂停/跳过时,您都想更新nowPlayingInfo。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接