Remove observer in setSrc if the source changes, but the view hasn't been removed from superview

Before: observer removes only in removeFromSuperview, but adds in setSrc – multiple setSrc would add multiple observers and one removeFromSuperview would remove only one observer. Now: Every addObserver in setSrc is balanced by removeObserver also in setSrc
This commit is contained in:
Stanisław Chmiela 2016-05-17 09:40:26 +02:00
parent 901f0cc9ab
commit 88e47159d7

View File

@ -225,6 +225,11 @@ static NSString *const playbackRate = @"rate";
_player = [AVPlayer playerWithPlayerItem:_playerItem]; _player = [AVPlayer playerWithPlayerItem:_playerItem];
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone; _player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
if (_playbackRateObserverRegistered) {
[_player removeObserver:self forKeyPath:playbackRate];
_playbackRateObserverRegistered = NO;
}
[_player addObserver:self forKeyPath:playbackRate options:0 context:nil]; [_player addObserver:self forKeyPath:playbackRate options:0 context:nil];
_playbackRateObserverRegistered = YES; _playbackRateObserverRegistered = YES;