I get w weird crash related to observing AVPlayer.timeControlStatus in iOS 13. It's not happening in iOS 12.
Here's the code for setting the observer up:
// stored in View Controller
private var playerStateObservation: NSKeyValueObservation?
@objc var player : AVPlayer?
// setting KVO after initialising AVPLayer
playerStateObservation = observe(\.player?.timeControlStatus) { [weak self] (object, change) in
let playing = self?.player?.timeControlStatus == .playing
self?.showPlayIcon(playing)
}
And here the function to stop observation. It's called in ViewController deinit.
func cleanUpObserver() {
playerStateObservation?.invalidate()
playerStateObservation = nil
}
The crash occurs in following situation:
- Open ViewController with AVPlayer and start observation.
- Go back to previous ViewController.
- Dismiss the app to the background.
- Bring back the app to the foreground.
- Crash:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x2b1bc593c)
Here's the callstack of the crash.
Looks like the AVPlayer is trying to send notification to a observer that should already be invalidated and released from memory. Did anyone have a similar issue?
