Audio playback progress as UISlider in Swift

前端 未结 4 1043
心在旅途
心在旅途 2021-01-31 10:28

I\'ve seen some posts about accomplishing this in Objective-C but I\'ve been unable to do the same via Swift.

Specifically, I can\'t figure out how to implement a

4条回答
  •  离开以前
    2021-01-31 11:13

    Syntax has now changed in Swift 4:

    updater = CADisplayLink(target: self, selector: #selector(self.trackAudio))
    updater.preferredFramesPerSecond = 1
    updater.add(to: RunLoop.current, forMode: RunLoopMode.commonModes)
    

    And the function (I have previously set the progressSlider.maxValue to player.duration):

    @objc func trackAudio() {
        progressSlider.value = Float(player!.currentTime)
     }
    

提交回复
热议问题