Hi there I'm using KVO to observe AvPlayer states, i am using instances of AVPlayer in different controllers, and observing them usign KVO.(Ex home controller has player and its observers and category controller has player and its observers, etc). I have a centralized class of Constants where i put the obsever contests like :
static void const *kCurrentItemDidChangeKVO = &kCurrentItemDidChangeKVO;
static void const *kRateDidChangeKVO = &kRateDidChangeKVO;
static void const *kStatusDidChangeKVO = &kStatusDidChangeKVO;
in each controller i add observers like:
if (player != nil)
{
[player addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:&kRateDidChangeKVO];
[player addObserver:self forKeyPath:@"currentItem.status" options:NSKeyValueObservingOptionNew context:&kStatusDidChangeKVO];
[player addObserver:self forKeyPath:@"currentItem.duration" options:NSKeyValueObservingOptionNew context:&kDurationDidChangeKVO];
}
and remove observers in each controller like:
if (player != nil)
{
[player removeObserver:self forKeyPath:@"rate" context:&kRateDidChangeKVO];
[player removeObserver:self forKeyPath:@"currentItem.status" context:&kStatusDidChangeKVO];
[player removeObserver:self forKeyPath:@"currentItem.duration" context:&kDurationDidChangeKVO];
}
and in each AVPlayer
i add and remove observers when that class(ViewController) is viewed, visited, viewWillAppeard or viewWillDissapeared using same contexts from Constants file.
My Question is: It is fine using same contexts from a centralized Constants file for each class containing player observer or should each class have their own contexts unique for that class?.
Any help is very appreciated. Regards