在哪里可以找到AVPlayer的可观察属性列表? 我似乎无法在Apple文档的任何地方找到它。
答案 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
中有关属性的注释明确说明哪些属性是键值可观察的:status
和outputObscuredDueToInsufficientExternalProtection
:
/*!
@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