Search code examples
objective-ccocoa-touchavaudioplayerkey-value-observing

KVO AVAudioPlayer not working


I am trying to observe the "currentTime" property of AVAudioPlayer. But the method isn't even being called... I need it to set the position of a UISlider.. But it's not working. Here's the relevant code:

[audioPlayer addObserver:self forKeyPath:@"currentTime" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];


- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {
    NSLog(@"%@", change);
}

Thanks.


Solution

  • I believe currentTime is not KVO compliant check the header.

    In any event, you can just start a NSTimer at your desired frequency and update your UI that way.