cvdogan
cvdogan

Reputation: 166

AVPlayer addPeriodicTimeObserver does not print all values

I am trying to use 1/50 sec interval in my AVPlayer time observer. But that does not print all values.

let interval = CMTimeMake(1, 50)    
AVPlayerVC.player?.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main, using: {(progressTime) in

  let seconds = CMTimeGetSeconds(progressTime)
  let doubleSeconds = String(format: "%.2f", seconds)
  print ("\(doubleSeconds) -")

This is the result: 0.00 - 0.05 - 0.09 - 0.13 - 0.21 - 0.30 - 0.40 - 0.45 - 0.54 - 0.59 - 0.70 - 0.75 - 0.85 - 0.96 - 1.07

How can I have every 0.02 second? (0.00 - 0.02 - 0.04 - 0.06 ...)

Upvotes: 0

Views: 493

Answers (1)

Dave Weston
Dave Weston

Reputation: 6635

As the documentation states, your callback is not guaranteed to get called as frequently as you request:

If the interval corresponds to a very short interval in real time, the player may invoke the block less frequently than requested. Even so, the player will invoke the block sufficiently often for the client to update indications of the current time appropriately in its end-user interface.

What are you trying to accomplish that you want to be notified so frequently?

Upvotes: 2

Related Questions