更改滑块值的播放器视图控制器时更新控制中心播放搜索

时间:2018-08-20 08:40:57

标签: ios swift

当更改播放媒体的控制中心位置时,我必须更改滑块值...

 commandCenter.changePlaybackPositionCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
        let event = event as! MPChangePlaybackPositionCommandEvent
        let time = CMTime(seconds: event.positionTime, preferredTimescale: self.player.currentTime().timescale)
        self.player.seek(to: time)
        return .success;
    }

@IBAction func handleSliderChange(_ sender: UISlider) {
        let seconds : Int64 = Int64(sender.value)
        let targetTime:CMTime = CMTimeMake(seconds, 1)
        myPlayer.player.seek(to: targetTime)
    }

@IBAction func sliderTapped(_ sender: UILongPressGestureRecognizer) {
    if let slider = sender.view as? UISlider {
        if slider.isHighlighted { return }
        let point = sender.location(in: slider)
        let percentage = Float(point.x / slider.bounds.width)
        let delta = percentage * (slider.maximumValue - slider.minimumValue)
        let value = slider.minimumValue + delta
        slider.setValue(value, animated: false)
        let seconds : Int64 = Int64(value)
        let targetTime: CMTime = CMTimeMake(seconds, 1)
        self.myPlayer.player.seek(to: targetTime)
    }
}

但是,在逆方法中,我不知道该怎么办。我想在更改滑块值时更新当前时间。

0 个答案:

没有答案