sahin/VideoSplashKit

AVPlayer observer error

Closed this issue · 5 comments

When running on ios 9 i am getting an error, an instance 0x7fd8f1395bb0 of class AVPlayer was deallocated while key value observers were still registered with it.
This happens after the view controller has gone out of focus and another view controller is presented.

I couldn't catch the error, could you please share the console output?

I think it happens when you present a modal view controller with a video and dismiss it, a few seconds later(i guess the cleanup happens) then the crash occurs.
2015-10-16 07:06:01.441 [59646:3758352] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7faa3b5dc050 of class AVPlayer was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7faa3b5519b0> (
<NSKeyValueObservance 0x7faa3b5dcfc0: Observer: 0x7faa37fc11b0, Key path: status, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x7faa3b5455e0>
)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103c3cf65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001077c3deb objc_exception_throw + 48
2 CoreFoundation 0x0000000103c3ce9d +[NSException raise:format:] + 205
3 Foundation 0x0000000104541b91 NSKVODeallocate + 294
4 libobjc.A.dylib 0x00000001077d7afe _ZN11objc_object17sidetable_releaseEb + 232
5 AVFoundation 0x0000000103065c6a -[AVPlayerLayer dealloc] + 114
6 Foundation 0x0000000104541ac9 NSKVODeallocate + 94
7 QuartzCore 0x0000000104f41683 _ZN2CA5Layer16free_transactionEPNS_11TransactionE + 191
8 QuartzCore 0x0000000104f65a7b _ZN2CA11Transaction6commitEv + 647
9 QuartzCore 0x0000000104f66154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
10 CoreFoundation 0x0000000103b689d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 23
11 CoreFoundation 0x0000000103b68947 __CFRunLoopDoObservers + 391
12 CoreFoundation 0x0000000103b5e59b __CFRunLoopRun + 1147
13 CoreFoundation 0x0000000103b5de98 CFRunLoopRunSpecific + 488
14 GraphicsServices 0x000000010a8acad2 GSEventRunModal + 161
15 UIKit 0x00000001054b9676 UIApplicationMain + 171
16 **** 0x0000000101e6d8bf main + 111
17 libdyld.dylib 0x000000010905292d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Sorry I did not catch the error, I'm working on..

Hello.

I'm dealing with the same issue here. The easiest way to deal with it is removing the KV observer when the instance is getting deinitialized, like this, it works like a charm.

VideoSplashViewController.swift

deinit{
        self.moviePlayer.player?.removeObserver(self, forKeyPath: "status")
}

Regards.

Hi @minuscorp,
Is it possible you can send this PR?