objective-c - KVO AVAudioPlayer 不工作

标签 objective-c cocoa-touch avaudioplayer key-value-observing

我正在尝试观察 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);
}

谢谢。

最佳答案

我相信 currentTime 不符合 KVO,请检查标题。

在任何情况下,您都可以按您想要的频率启动 NSTimer 并以此方式更新您的 UI。

关于objective-c - KVO AVAudioPlayer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5930854/

相关文章:

ios - CSSMERR_TP_NOT_TRUSTED 错误

iphone - UITableview 重新加载部分标题而不是部分中的单元格

cocoa-touch - 使用 RestKit 进行轻量级迁移

ios - 播放音频甚至应用程序从后台删除

ios - View Controller Containment 共享父对象

ios - 二进制表达式 ('CGFloat'(又名 'double')和 'UIView * _Nullable' 的无效操作数)

iphone - 执行 startAnimating 时的 UIImageView 动画延迟

iphone - 在 Objective-C (iOS) 中测试内存管理

iphone - AVAudioPlayer 后台任务不起作用 [iOS]

iphone - 当声音在 AVAudioPlayer 中播放完毕时执行操作吗?