如何设置 MPRemoteCommandEvent 的播放时间?

How to set the playback time from MPRemoteCommandEvent?

我有代码回调:

commandCenter.changePlaybackPositionCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in

        self.player.currentTime = ???
        self.setupNowPlaying(img: self.image)
        return .success
    }

它被调用了。但是我如何设置它应该开始播放的实际时间。该事件似乎没有给我用户拖动到的时间。我如何获得该值?

The event does not seem to give me the time where the user dragged to

是的。 event 有一个 positionTime.

将事件转换为 MPChangePlaybackPositionCommandEvent。

MPChangePlaybackPositionCommandEvent 有一个 positionTime 属性,这是播放位置。

commandCenter.changePlaybackPositionCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in

    if let changePlaybackPositionCommandEvent = event as? MPChangePlaybackPositionCommandEvent
    {
        let positionTime = changePlaybackPositionCommandEvent.positionTime      
        self.player.currentTime = positionTime   
        return .success
    }
}

如上所示,对于所有事件,您必须将其转换为与命令匹配的事件类型,然后在将事件转换为 MPChangePlaybackPositionCommandEvent 后,您会在 values.You 从 event.positionTime 获取时间 skip 的另一个例子是 let event = event as! MSPkipIntervalCommandEvent