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时,我将检查是否存在最后一个,并删除
但是我得到了
       -[AVPlayerItem removeObserver:forKeyPath:]:发送到已释放实例的消息

有人知道为什么吗?

最佳答案

在某些时候,mPlayerItem指向的对象被释放,但是mPlayerItem未被设置为nil。寻找您可能无法充分保留或过度释放玩家实例的地方。

09-27 07:52