I’m implementing a feature for a tvOS app and it keeps crashing with unrecognized selector.
The app has a VideoPlayerBase
class in objc and both iOS's VideoPlayerController.swift
and tvOS's VideoPlayerController.swift
are inherited from the base class. I need to set AVPlayerItem.externalMetaData once the video is loaded up. However, when I try to call AVPlayerItem.externalMetaData, it crashes.
If I set break point in BasePlayerController.m
and do po player.currectItem.externalMetaData
in console, I'll get this error
error: property 'externalMetadata' not found on object of type 'AVPlayerItem *'
error: 1 errors parsing expression
And then it will crash with this line
self.playerController.player.currentItem?.externalMetadata = episode.metadataItems
The call stack:
2016-10-28 09:51:33.808 App[14081:103783] -[AVPlayerItem setExternalMetadata:]: unrecognized selector sent to instance 0x608000214e10
2016-10-28 09:51:33.827 App[14081:103783] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVPlayerItem setExternalMetadata:]: unrecognized selector sent to instance 0x608000214e10'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109b00b1b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010920421e objc_exception_throw + 48
2 CoreFoundation 0x0000000109b702d4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000109a863e5 forwarding + 1013
4 CoreFoundation 0x0000000109a85f68 _CF_forwarding_prep_0 + 120
5 ***App 0x0000000105baebd0 TFC6AMCApp21VideoPlayerController21playerDidStartPlayingfT_T + 848
6 ***App 0x0000000105baec72 TToFC6AMCApp21VideoPlayerController21playerDidStartPlayingfT_T + 34
7 ***App 0x0000000105b33e38 -[PlayerController play] + 216
8 ***App 0x0000000105b364e8 __42-[PlayerController playerReadyForPlayback]_block_invoke + 952
9 libdispatch.dylib 0x000000010a5c1980 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000010a5eb0cd _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000010a5cb8d6 _dispatch_main_queue_callback_4CF + 406
12 CoreFoundation 0x0000000109ac4cc9 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
13 CoreFoundation 0x0000000109a8a75d __CFRunLoopRun + 2205
14 CoreFoundation 0x0000000109a89c64 CFRunLoopRunSpecific + 420
15 GraphicsServices 0x000000010d12da6f GSEventRunModal + 161
16 UIKit 0x00000001067eb612 UIApplicationMain + 159
17 ***App 0x0000000105b91562 main + 114
18 libdyld.dylib 0x000000010a637749 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
However, if I set a break point before or on the line self.playerController.player.currentItem?.externalMetadata = episode.metadataItems
and do a po
in console po self.playerController.player.currentItem?.externalMetadata
. I’ll get this
(lldb) po self.playerController.player.currentItem?.externalMetadata
▿ Optional<Array<AVMetadataItem>>
- Some : 0 elements
Continuing from this line won’t crash anything!!!!!!!
I'm aware that externalMetadata
property is a tvOS only property and I have AVFoundation
, AVKit
both import in my objc file and swift file.
I spent whole day yesterday and didn't get this solved :(