title: periodicTimeObserver for duration countdown in AVPlayer with Swift
body: <p>I have a time observer for AVPlayer that works great.  Im trying to get it to countdown from the duration of the audio 0.</p>
  
  <p>It works and does count down now I'm just having some trouble with formatting.</p>
  
  <p>if you see the picture below you'll see what i mean.  It goes from whole minutes:seconds 3:00, to weird numbers 3:-1 ect.</p>
  
  <p><a href="https://i.stack.imgur.com/rkf9n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rkf9n.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/QsVG2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QsVG2.png" alt="enter image description here"></a></p>
  
  <p>any ideas what I've done wrong?</p>
  
  <p>heres the code for the timer:</p>
  
  <pre><code>let interval = CMTime(value: 1, timescale: 1)
  self.audioPlayer?.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main, using: { (progressTime) in
  
  let secondsProgress = CMTimeGetSeconds(progressTime)
  
      let secondsStringProgress = String(format: "%02d", Int((secondsProgress.truncatingRemainder(dividingBy: 60))))
      let minuitesStringProgress = String(format: "%02d", Int(secondsProgress) / 60)
      //self.countDownLabel.text = "\(minuitesStringProgress):\(secondsStringProgress)"
  
      if let duration = self.audioPlayer?.currentItem!.asset.duration {
  
          let secondsDuration = CMTimeGetSeconds(duration)
  
              let secondsStringDuration = String(format: "%02d", Int((secondsDuration.truncatingRemainder(dividingBy: 60))))
              let minuitesStringDuration = String(format: "%02d", Int(secondsDuration) / 60)
  
                  let secondsString = String(format: "%02d", Int(secondsStringDuration)! - Int(secondsStringProgress)!)
                  let minuitesString = String(format: "%02d", Int(minuitesStringDuration)! - Int(minuitesStringProgress)!)
  
              self.countDownLabel.isHidden = false
              self.countDownLabel.text = "\(minuitesString):\(secondsString)"
  
          self.horizontalSlider.value = Float(secondsProgress / secondsDuration)
          self.circleSlider.value = Float(secondsProgress / secondsDuration)
  
      }
  })
  </code></pre>