如果我想用KVO来观察我的播放器项目,可以像这样:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
两个问题:
1)当项目完成播放时(即在AVPlayerItemDidPlayToEndTimeNotification
中),我需要删除观察者吗?
2)如果我调用[_avQueuePlayer removeAllItems]
,它是否也会删除每个项目的观察者?