DFPlayer icon indicating copy to clipboard operation
DFPlayer copied to clipboard

Cannot remove an observer产生的崩溃

Open yuhengZhu opened this issue 5 years ago • 0 comments

Cannot remove an observer <DFPlayer 0x2811e1700> for the key path "status" from <AVPlayerItem 0x282ff5220> because it is not registered as an observer. (null)

_playerItem removeObserver的时候发生的崩溃,这种崩溃怎么来查呢。涉及到的具体代码:

  • (void)setPlayerItem:(AVPlayerItem *)playerItem{ if (_playerItem == playerItem) { return; } if (_playerItem) { [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil]; [_playerItem removeObserver:self forKeyPath:DFStatusKey]; [_playerItem removeObserver:self forKeyPath:DFLoadedTimeRangesKey]; [_playerItem removeObserver:self forKeyPath:DFPlaybackBufferEmptyKey]; [_playerItem removeObserver:self forKeyPath:DFPlaybackLikelyToKeepUpKey]; } _playerItem = playerItem; if (playerItem) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(df_playerDidPlayToEndTime:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil]; [playerItem addObserver:self forKeyPath:DFStatusKey options:NSKeyValueObservingOptionNew context:nil]; [playerItem addObserver:self forKeyPath:DFLoadedTimeRangesKey options:NSKeyValueObservingOptionNew context:nil]; [playerItem addObserver:self forKeyPath:DFPlaybackBufferEmptyKey options:NSKeyValueObservingOptionNew context:nil]; [playerItem addObserver:self forKeyPath:DFPlaybackLikelyToKeepUpKey options:NSKeyValueObservingOptionNew context:nil]; } }

yuhengZhu avatar Aug 19 '20 02:08 yuhengZhu