KVO物业清单?

时间:2015-12-23 18:46:05

标签: ios avplayer key-value-observing

在哪里可以找到AVPlayer的可观察属性列表? 我似乎无法在Apple文档的任何地方找到它。

2 个答案:

答案 0 :(得分:2)

只有当文档告诉您这是安全/正确的行为时,才能使用KVO。基本上,要获得列表,您只需要搜索“可观察”或“观察”或“观察”这个词。

因此,对于AVPlayer,咨询the docs,在status属性文档下,我们读到:

  

此属性是可观察的关键值使用键值观察

同样,在outputObscuredDueToInsufficientExternalProtection属性文档下,我们读到:

  

您可以使用键值观察

观察此属性值的更改

因此,答案是:AVPlayer的status属性及其outputObscuredDueToInsufficientExternalProtection属性,而不是其他属性,是键值可观察的。

但请注意,还有其他方式可以通知AVPlayer的内容,例如:致电addPeriodicTimeObserverForInterval:queue:usingBlock:addBoundaryTimeObserverForTimes:queue:usingBlock:

答案 1 :(得分:1)

AVPlayer Programing Guide显示KVO status键,以及AVPlayerItem的可观察通知:AVPlayerItemDidPlayToEndTimeNotification等。

可以在通知下的AVPlayerItem docs中找到AVPlayerItem可观察通知的完整列表。

AVPlayerItemDidPlayToEndTimeNotification
AVPlayerItemFailedToPlayToEndTimeNotification
AVPlayerItemTimeJumpedNotification
AVPlayerItemPlaybackStalledNotification
AVPlayerItemNewAccessLogEntryNotification
AVPlayerItemNewErrorLogEntryNotification

此外,AVPlayer.h中有关属性的注释明确说明哪些属性是键值可观察的:statusoutputObscuredDueToInsufficientExternalProtection

/*!
 @property status
 @abstract
    The ability of the receiver to be used for playback.

 @discussion
    The value of this property is an AVPlayerStatus that indicates whether the receiver can be used for playback. When
    the value of this property is AVPlayerStatusFailed, the receiver can no longer be used for playback and a new
    instance needs to be created in its place. When this happens, clients can check the value of the error property to
    determine the nature of the failure. This property is key value observable.
 */
@property (nonatomic, readonly) AVPlayerStatus status;

// ...

@interface AVPlayer (AVPlayerProtectedContent)

/*!
    @property outputObscuredDueToInsufficientExternalProtection
    @abstract
        Whether or not decoded output is being obscured due to insufficient external protection.

    @discussion
        The value of this property indicates whether the player is purposefully obscuring the visual output
        of the current item because the requirement for an external protection mechanism is not met by the
        current device configuration. It is highly recommended that clients whose content requires external
        protection observe this property and set the playback rate to zero and display an appropriate user
        interface when the value changes to YES. This property is key value observable.

        Note that the value of this property is dependent on the external protection requirements of the
        current item. These requirements are inherent to the content itself and cannot be externally specified.
        If the current item does not require external protection, the value of this property will be NO.
 */
@property (nonatomic, readonly) BOOL outputObscuredDueToInsufficientExternalProtection NS_AVAILABLE_IOS(6_0);

@end