KVO AVAudioPlayer无法正常工作

use*_*064 5 cocoa-touch objective-c key-value-observing avaudioplayer

我试图观察AVAudioPlayer的"currentTime"属性.但是这个方法甚至没有被调用...我需要它来设置UISlider的位置..但它不起作用.这是相关的代码:

[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);
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

Nic*_*ick 5

我相信currentTime不符合KVO检查标题.

无论如何,您只需以所需频率启动NSTimer并以此方式更新UI.