Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Created February 21, 2019 10:01
Show Gist options
  • Save pgpt10/993398a3c70d219cde4c8e2288918eb8 to your computer and use it in GitHub Desktop.
Save pgpt10/993398a3c70d219cde4c8e2288918eb8 to your computer and use it in GitHub Desktop.
player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 2), queue: DispatchQueue.main) {[weak self] (progressTime) in
if let duration = player.currentItem?.duration {
let durationSeconds = CMTimeGetSeconds(duration)
let seconds = CMTimeGetSeconds(progressTime)
let progress = Float(seconds/durationSeconds)
DispatchQueue.main.async {
self?.progressBar.progress = progress
if progress >= 1.0 {
self?.progressBar.progress = 0.0
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment