Removing AVPlayerItem Observers

If I use KVO to monitor elements of my player, for example:

    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];

      

Two questions:

1) Do I need to remove my observers after finishing the game? (i.e. in AVPlayerItemDidPlayToEndTimeNotification

)

2) If I call [_avQueuePlayer removeAllItems]

, does it also remove the observers of each item?

+3


source to share


1 answer


make your player object (AVPlayerItem * playerItem) globally, set its property and synthesize it.

1) Do I need to remove my observers after finishing the game? (that is, in AVPlayerItemDidPlayToEndTimeNotification)

Yes, you need to remove all spectators when you are about to leave this view controller where this player is playing. Not after the end of the game.



2) If I call [_avQueuePlayer removeAllItems] does it also remove all item watchers?

Yes, it removes all observers that are set for this global variable.

+1


source







All Articles