Update the slider based on the audio Player time duration iOS Swift
First, you have to declare the updater.
var updater : CADisplayLink! = nil
var progress:UISlider!
Then add the target to the updater.
Code:
updater = CADisplayLink(target: self, selector: Selector("updateProgressView"))
updater = CADisplayLink(target: self, selector: Selector("updateProgressView"))
updater.frameInterval = 1
updater.add(to: RunLoop.current, forMode: RunLoopMode.defaultRunLoopMode)
Then implement the selector method.
Code:
func updateAudioProgressView()
func updateAudioProgressView()
{
if player.isPlaying
{
// Update progress
let total = Float(player.duration/60)
let current_time = Float(player.currentTime/60)
progress.minimumValue = 0.0
progress.maximumValue = Float(player.duration)
progress.setValue(Float(player.currentTime), animated: true)
}
}
Awesome, dude!!!
ReplyDeleteI didn't even seen this realization on Swift at SO. Cheers :)