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
    }

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

问题是:

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

4

1 回答 1

5

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

于 2019-03-18T18:36:16.760 回答