Update the slider based on the audio Player time duration iOS Swift


First, you have to declare the updater.
Code:
    var updater : CADisplayLink! = nil
    var progress:UISlider!
Then add the target to the updater.

Code:
            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()
    {
        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)            
        }
    }


Comments

  1. Awesome, dude!!!
    I didn't even seen this realization on Swift at SO. Cheers :)

    ReplyDelete

Post a Comment

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift