0
   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:]: message sent to deallocated instance

有谁知道为什么?

4

1 回答 1

2

在某些时候, 指向的对象mPlayerItem正在被释放,但mPlayerItem没有被设置为nil。寻找可能保留不足或过度释放播放器实例的地方。

于 2012-10-08T06:20:43.657 回答