正如我的对象中声明的对象:除去观察者的dealloc与
AVQueuePlayer *queuePlayer;
在代码我已经添加的观察者:
- (void) playStreamedTrack: (Track *) track {
[queuePlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
[queuePlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1, NSEC_PER_SEC)
queue:nil
usingBlock:^(CMTime time) {
progress = time.value/time.timescale;
}];
}
我试图除去观察者跟随,但不工作
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[queuePlayer removeObserver:self forKeyPath:@"status" context:nil];
}
我该如何删除观察者?
是否调用了'dealloc'? – trojanfoe 2014-09-22 07:09:21
是的,我使用的dealloc方法在上面。 控制台中的错误是: ***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'类AVQueuePlayer的实例0x7f970b55ae00被解除分配,而键值观察者仍在注册它。现有的观测信息:( 的语境:为0x0,物业:0x7f970b6fb390> )” –
2014-09-22 07:39:26
观察员注册了多少次?它看起来像是在错误的地方注册,如果这个“轨道”不止一次播放。 – trojanfoe 2014-09-22 07:41:58