4

I have this setup to observe value changes for AVCaptureDevice deviceWhiteBalanceGains:

@objc dynamic var videoDevice:AVCaptureDevice?
private var deviceWBGainsObservation: NSKeyValueObservation?

And then in the code,

deviceWBGainsObservation = videoDevice?.observe(\.deviceWhiteBalanceGains,
                     options: [.old, .new]) {[unowned self] (object, change) in

    NSLog("\(change)")
}

Problem is change oldValue and newValue is always nil. This is not the case if I use the traditional key-value observing method observeValue(forKeypath:...). What am I doing wrong?

Maciej Gad
  • 1,701
  • 16
  • 21
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • I can confirm this issue. I've encountered this, too. For now, my workaround is to observe `isAdjustingWhiteBalance` instead (works quite well and almost instantaneous). – robert Jan 14 '20 at 11:56
  • We are observing a similar issue with `AVPlayerItem.duration` and `AVPlayerItem.status` but not with other `AVPlayerItem` properties like `isPlaybackLikelyToKeepUp` or `isPlaybackBufferEmpty` – Juan Carlos Ospina Gonzalez Jul 17 '20 at 09:27
  • The traditional observeValue for keypath has a big problem. Sometimes it crashes by saying no observer is added for keyPath which I can not reproduce. I wish the Swift API for AVPlayer worked. – Deepak Sharma Jul 23 '20 at 18:11

0 Answers0