用AVPlayer做开发,KVO该释放的都释放了,检查了好几遍了。可在无网络状态下,连续开启几次播放器就会报错:
AVPlayerItem was deallocated while key value observers were still registered with it
dealloc本人是这么写的
[player removeObserver:self forKeyPath:@”rate” context:nil];
[player.currentItem removeObserver:self forKeyPath:@”status”];
[player.currentItem removeObserver:self forKeyPath:@”loadedTimeRanges”];
紧急求帮助。
AVPlayerItem was deallocated while key value observers were still registered with it
dealloc本人是这么写的
[player removeObserver:self forKeyPath:@”rate” context:nil];
[player.currentItem removeObserver:self forKeyPath:@”status”];
[player.currentItem removeObserver:self forKeyPath:@”loadedTimeRanges”];
紧急求帮助。
解决方案
15
连续开启几个播放器是反复push/pop某个页面么?
10
解决了就好
15
KVO使用不当,会出现很多这样那样的问题。如你上面所说,释放的时机不好把握。这里有一个比较好的第三方库对这种状态的管理有比较好的封装。它就是ReactiveCocoa, 一个非常优秀的状态管理的框架。它将KVO, NSNotificationCenter, target – action 这些统一了处理的接口