Is there a good way to use key-value-observation and blocks together? I have a function that takes a completion block, and I want this completion block to run when the observed status changes into AVPlayerItemStatusReadyToPlay
. Can I pass the block using the context of the observer somehow, or would this break the fundamentals of KVO programming?
- (void)setVideoWithURL:(NSURL *)url completed:(PlayerCompletedWithFinishedBlock)completedBlock {
...
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([change isEqual: @"AVPlayerItemStatusReadyToPlay"]) {
// Is there a way to run the completion block from here?
}
}