AVPlayerItem removeObserver:forKeyPath get error

时间:2012-10-08 05:40:12

标签: iphone objective-c ios

   if (mPlayerItem){
    [mPlayerItem removeObserver:self forKeyPath:kStatusKey];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:AVPlayerItemDidPlayToEndTimeNotification
                                                  object:mPlayerItem];
}

//create AVPlayerItem
NSURL *url = [self getUrlWithROAudio:audioFile];

mPlayerItem = [AVPlayerItem playerItemWithURL:url];
[mPlayerItem    addObserver:self
                forKeyPath:kStatusKey
                options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
                context:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:mPlayerItem];

当我创建一个新的AVPlayerItem时,我将检查最后一个是否存在,并检查removeObserver 但我得到了         - [AVPlayerItem removeObserver:forKeyPath:]:发送到解除分配的实例的消息

谁知道为什么?

1 个答案:

答案 0 :(得分:2)

在某些时候,mPlayerItem指向的对象正在发布,但mPlayerItem未设置为nil。寻找你可能保留或过度释放你的玩家实例的地方。