1

我正在为 tvOS 应用程序实现一项功能,但它不断因无法识别的选择器而崩溃。

该应用程序VideoPlayerBase在 objc 中有一个类,iOSVideoPlayerController.swift和 tvOSVideoPlayerController.swift都继承自基类。加载视频后,我需要设置 AVPlayerItem.externalMetaData 。但是,当我尝试调用 AVPlayerItem.externalMetaData 时,它会崩溃。

如果我在控制台中设置断点BasePlayerController.mpo player.currectItem.externalMetaData在控制台中执行,我会收到此错误

错误:在“AVPlayerItem *”类型的对象上找不到属性“externalMetadata”

error: 1 解析表达式错误

然后它将与这条线崩溃

self.playerController.player.currentItem?.externalMetadata = episode.metadataItems

调用堆栈:

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)

但是,如果我在行之前或行上设置断点self.playerController.player.currentItem?.externalMetadata = episode.metadataItemspo在控制台中执行po self.playerController.player.currentItem?.externalMetadata。我会得到这个

(lldb) po self.playerController.player.currentItem?.externalMetadata
▿ Optional<Array<AVMetadataItem>>
  - Some : 0 elements

从这条线继续不会崩溃任何东西!!!!!!!

我知道该externalMetadata属性是仅 tvOS 的属性,并且我有AVFoundationAVKit都导入到我的 objc 文件和 swift 文件中。

我昨天花了一整天都没有解决这个问题:(

4

1 回答 1

0

您需要换行,其中包含externalMetadata如下属性AVPlayerItem

#if TARGET_OS_TV
    self.playerController.player.currentItem?.externalMetadata = episode.metadataItems
#endif

或在适当类别的Target Membership部分中仅选择tvOS目标

于 2017-01-19T16:16:36.690 回答