首页 技术 正文
技术 2022年11月16日
0 收藏 449 点赞 2,844 浏览 2023 个字

Xcode Consolu打印出来的提示:

An instance 0x156608c0 of class AVPlayer was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here’s the current observation info:

<NSKeyValueObservationInfo 0x15634320> (

<NSKeyValueObservance 0x15597fa0: Observer: 0x15674660, Key path: currentItem, Options: <New: YES, Old: NO, Prior: NO> Context: 0x134cc4, Property: 0x1558ff20>

<NSKeyValueObservance 0x15598da0: Observer: 0x15674660, Key path: rate, Options: <New: YES, Old: NO, Prior: NO> Context: 0x134cc0, Property: 0x1559ad40>

提示的说明了AVPlayer这个类已经被释放了,当已经登记了消息监听还登记着,这可能会引起消息的泄漏,我的解决办法是在移除视图之前取消监听时间.

AVPlayer的监听部分代码:

  [self setPlayer:[AVPlayer playerWithPlayerItem:self.playerItem]];        /* Observe the AVPlayer "currentItem" property to find out when any
AVPlayer replaceCurrentItemWithPlayerItem: replacement will/did
occur.*/
[self.player addObserver:self
forKeyPath:kCurrentItemKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVARLDelegateDemoViewControllerCurrentItemObservationContext]; /* Observe the AVPlayer "rate" property to update the scrubber control. */
[self.player addObserver:self
forKeyPath:kRateKey    
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVARLDelegateDemoViewControllerRateObservationContext];
 [self.playerItem addObserver:self
  
              forKeyPath:kStatusKey
                options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew

                          context:AVARLDelegateDemoViewControllerStatusObservationContext];
 

解决办法:

- (void)viewWillDisappear:(BOOL)animated{
NSLog(@"Disappear");
  if(self.playerItem && self.player){
    [self.playerItem removeObserver:self forKeyPath:kStatusKey context:AVARLDelegateDemoViewControllerStatusObservationContext];
    
   [self.player removeObserver:self forKeyPath:kRateKey context:AVARLDelegateDemoViewControllerRateObservationContext];
     [self.player removeObserver:self forKeyPath:kCurrentItemKey context:AVARLDelegateDemoViewControllerCurrentItemObservationContext];
}
上一篇: hdp 2.06 安装备忘
下一篇: YY的GCD 数学
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,427
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,244
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,687
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726