【发布时间】:2016-03-30 06:06:00
【问题描述】:
在哪里可以找到 AVPlayer 的可观察属性列表? 我似乎在 Apple 文档中的任何地方都找不到它。
【问题讨论】:
-
我们能找到 NSString 或 NSArray 的 KVO 属性吗?
-
如果有人帮助了你,你应该接受一个答案。
标签: ios avplayer key-value-observing
在哪里可以找到 AVPlayer 的可观察属性列表? 我似乎在 Apple 文档中的任何地方都找不到它。
【问题讨论】:
标签: ios avplayer key-value-observing
只有在文档告诉您这是安全/正确的行为时,您才能使用 KVO。基本上,要获得您的列表,您只需搜索“observable”或“observe”或“observing”这个词。
因此,对于 AVPlayer,请咨询 the docs,在 status 属性文档下,我们阅读:
这个属性是键值可观察的使用键值观察
同样,在outputObscuredDueToInsufficientExternalProtection 属性文档下,我们阅读:
您可以使用键值观察来观察此属性值的变化
因此,答案是:AVPlayer 的 status 属性和它的 outputObscuredDueToInsufficientExternalProtection 属性以及其他任何属性都是键值可观察的。
但是,请注意,还有其他方式可以通知 AVPlayer 的情况,例如通过调用addPeriodicTimeObserverForInterval:queue:usingBlock: 或addBoundaryTimeObserverForTimes:queue:usingBlock:。
【讨论】:
outputObscuredDueToInsufficientExternalProtection 属性在 AVPlayer 上也是可以观察到的键值对。
AVPlayer Programing Guide 显示 KVO status 键,以及AVPlayerItem 的可观察通知:AVPlayerItemDidPlayToEndTimeNotification 等。
AVPlayerItem 可观察通知的完整列表可在通知下的AVPlayerItem docs 中找到。
AVPlayerItemDidPlayToEndTimeNotification
AVPlayerItemFailedToPlayToEndTimeNotification
AVPlayerItemTimeJumpedNotification
AVPlayerItemPlaybackStalledNotification
AVPlayerItemNewAccessLogEntryNotification
AVPlayerItemNewErrorLogEntryNotification
此外,AVPlayer.h 中属性的 cmets 明确说明了哪些属性是键值可观察的: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
【讨论】: