From 88e47159d766f2a00956b4e65a805cfb450c3aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Tue, 17 May 2016 09:40:26 +0200 Subject: [PATCH] Remove observer in setSrc if the source changes, but the view hasn't been removed from superview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- RCTVideo.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RCTVideo.m b/RCTVideo.m index 5a6d80d5..4fc9cf66 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -225,6 +225,11 @@ static NSString *const playbackRate = @"rate"; _player = [AVPlayer playerWithPlayerItem:_playerItem]; _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; + + if (_playbackRateObserverRegistered) { + [_player removeObserver:self forKeyPath:playbackRate]; + _playbackRateObserverRegistered = NO; + } [_player addObserver:self forKeyPath:playbackRate options:0 context:nil]; _playbackRateObserverRegistered = YES;