Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 926
user635064 Avatar asked May 08 '11 22:05

user635064


1 Answers

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.

like image 188
Nick Avatar answered Oct 03 '22 10:10

Nick