From 5506805aac9c5888c405a169b0d3240faf4c1913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Tue, 17 May 2016 09:37:11 +0200 Subject: [PATCH 1/7] Add playbackRateObserverRegistered bool property --- RCTVideo.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RCTVideo.m b/RCTVideo.m index a45fa7d6..46f691bc 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -22,6 +22,7 @@ static NSString *const playbackRate = @"rate"; /* Required to publish events */ RCTEventDispatcher *_eventDispatcher; + BOOL _playbackRateObserverRegistered; bool _pendingSeek; float _pendingSeekTime; @@ -49,6 +50,7 @@ static NSString *const playbackRate = @"rate"; if ((self = [super init])) { _eventDispatcher = eventDispatcher; + _playbackRateObserverRegistered = NO; _playbackStalled = NO; _rate = 1.0; _volume = 1.0; From 901f0cc9ab2d90aa275073ebad1e91969991797d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Tue, 17 May 2016 09:38:35 +0200 Subject: [PATCH 2/7] Save current state of observing in _playbackRateObserverRegistered property --- RCTVideo.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RCTVideo.m b/RCTVideo.m index 46f691bc..5a6d80d5 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -226,6 +226,7 @@ static NSString *const playbackRate = @"rate"; _player = [AVPlayer playerWithPlayerItem:_playerItem]; _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; [_player addObserver:self forKeyPath:playbackRate options:0 context:nil]; + _playbackRateObserverRegistered = YES; const Float64 progressUpdateIntervalMS = _progressUpdateInterval / 1000; // @see endScrubbing in AVPlayerDemoPlaybackViewController.m of https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html @@ -669,7 +670,8 @@ static NSString *const playbackRate = @"rate"; - (void)removeFromSuperview { [_player pause]; - [_player removeObserver:self forKeyPath:playbackRate]; + [_player removeObserver:self forKeyPath:playbackRate]; + _playbackRateObserverRegistered = NO; _player = nil; [self removePlayerLayer]; 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 3/7] 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; From e7337227fea2152920dfcecce9d6873f708f3041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Tue, 17 May 2016 09:40:58 +0200 Subject: [PATCH 4/7] Remove observer only if it has been registered Happens if someone creates Video component, but doesn't set src to it. --- RCTVideo.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RCTVideo.m b/RCTVideo.m index 4fc9cf66..364560ed 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -675,8 +675,10 @@ static NSString *const playbackRate = @"rate"; - (void)removeFromSuperview { [_player pause]; + if (_playbackRateObserverRegistered) { [_player removeObserver:self forKeyPath:playbackRate]; _playbackRateObserverRegistered = NO; + } _player = nil; [self removePlayerLayer]; From b6dc7c469b46f805d03f561d1f430ea713a9b36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Thu, 19 May 2016 20:27:23 +0200 Subject: [PATCH 5/7] Remove observer providing context --- RCTVideo.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 364560ed..7e48fb4d 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -227,7 +227,7 @@ static NSString *const playbackRate = @"rate"; _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; if (_playbackRateObserverRegistered) { - [_player removeObserver:self forKeyPath:playbackRate]; + [_player removeObserver:self forKeyPath:playbackRate context:nil]; _playbackRateObserverRegistered = NO; } [_player addObserver:self forKeyPath:playbackRate options:0 context:nil]; @@ -676,7 +676,7 @@ static NSString *const playbackRate = @"rate"; { [_player pause]; if (_playbackRateObserverRegistered) { - [_player removeObserver:self forKeyPath:playbackRate]; + [_player removeObserver:self forKeyPath:playbackRate context:nil]; _playbackRateObserverRegistered = NO; } _player = nil; From edf3a8c5799f2bf2440b1e4d1dfb19b907f7f238 Mon Sep 17 00:00:00 2001 From: Don Nguyen Date: Fri, 27 May 2016 15:56:16 +0700 Subject: [PATCH 6/7] Remove observer of player before calling playerWithPlayerItem It makes no sense if we move observer after calling calling playerWithPlayerItem because this is where the exception raises --- RCTVideo.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 7e48fb4d..4221fe76 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -223,13 +223,14 @@ static NSString *const playbackRate = @"rate"; [_playerViewController.view removeFromSuperview]; _playerViewController = nil; - _player = [AVPlayer playerWithPlayerItem:_playerItem]; - _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; - if (_playbackRateObserverRegistered) { [_player removeObserver:self forKeyPath:playbackRate context:nil]; _playbackRateObserverRegistered = NO; } + + _player = [AVPlayer playerWithPlayerItem:_playerItem]; + _player.actionAtItemEnd = AVPlayerActionAtItemEndNone; + [_player addObserver:self forKeyPath:playbackRate options:0 context:nil]; _playbackRateObserverRegistered = YES; From 242b79ac385736cc3d420f46e9df227eff40a9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Mon, 30 May 2016 17:03:47 +0200 Subject: [PATCH 7/7] Publish new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f63726c..0f823988 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "0.8.0-rc", + "version": "0.8.0", "description": "A