更新时间:2023-11-08 08:24:10
您可以为这些键添加观察者:
you can add observer for those keys:
[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
第一个会在您的缓冲区为空时警告您,第二个会在您的缓冲区可以再次使用时发出警告.
The first one will warn you when your buffer is empty and the second when your buffer is good to go again.
然后要处理密钥更改,您可以使用以下代码:
Then to handle the key change you can use this code:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (!player)
{
return;
}
else if (object == playerItem && [keyPath isEqualToString:@"playbackBufferEmpty"])
{
if (playerItem.playbackBufferEmpty) {
//Your code here
}
}
else if (object == playerItem && [keyPath isEqualToString:@"playbackLikelyToKeepUp"])
{
if (playerItem.playbackLikelyToKeepUp)
{
//Your code here
}
}
}