我有一个UISliderAvAudioPlayer,目前我可以将UISlider设置为currentTimeAvAudioPlayer,如下所示:

timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: (#selector(RecordController.updateTimer)), userInfo: nil, repeats: true)

@objc func updateTimer() {
    if(audio != nil) {
       audioSlider.setValue(Float((self.audio?.currentTime)! / (self.audio?.duration)!), animated: false)
    }
}

但是,在更改currentTime的值时,如何设置AVAudioPlayerUISlider
@IBAction func audioSliderUpdated(_ sender: Any) {
}

最佳答案

您可以使用AVAudioPlayer的currentTime属性:

@IBAction func audioSliderUpdated(_ sender: Any) {
  if let slider = sender as? UISlider {
    self.audio?.currentTime = slider.value
  }
}

关于ios - Swift 4-AVAudioPlayer从UISlider设置currentTime,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51256517/

10-13 02:24