You will need to use KVO to do this.
For each item added to the queue, you can configure observers as follows:
item_ = [[AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://somefunkyurl"]] retain]; [item_ addObserver:self forKeyPath:@"status" options:0 context:nil]; [item_ addObserver:self forKeyPath:@"playbackBufferEmpty" options:0 context:nil];
Now you can evaluate the status of this element in the observer method;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([object isKindOfClass:[AVPlayerItem class]]) { AVPlayerItem *item = (AVPlayerItem *)object; //playerItem status value changed? if ([keyPath isEqualToString:@"status"]) { //yes->check it... switch(item.status) { case AVPlayerItemStatusFailed: NSLog(@"player item status failed"); break; case AVPlayerItemStatusReadyToPlay: NSLog(@"player item status is ready to play"); break; case AVPlayerItemStatusUnknown: NSLog(@"player item status is unknown"); break; } } else if ([keyPath isEqualToString:@"playbackBufferEmpty"]) { if (item.playbackBufferEmpty) { NSLog(@"player item playback buffer is empty"); } } } }
source share