diff --git a/Examples/VideoPlayer/VideoPlayer.xcodeproj/project.xcworkspace/xcuserdata/brentvatne.xcuserdatad/UserInterfaceState.xcuserstate b/Examples/VideoPlayer/VideoPlayer.xcodeproj/project.xcworkspace/xcuserdata/brentvatne.xcuserdatad/UserInterfaceState.xcuserstate
index 8f2980c9..01791fee 100644
Binary files a/Examples/VideoPlayer/VideoPlayer.xcodeproj/project.xcworkspace/xcuserdata/brentvatne.xcuserdatad/UserInterfaceState.xcuserstate and b/Examples/VideoPlayer/VideoPlayer.xcodeproj/project.xcworkspace/xcuserdata/brentvatne.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Examples/VideoPlayer/node_modules/react-native-video/RCTVideo.xcodeproj/xcuserdata/brentvatne.xcuserdatad/xcschemes/xcschememanagement.plist b/Examples/VideoPlayer/node_modules/react-native-video/RCTVideo.xcodeproj/xcuserdata/brentvatne.xcuserdatad/xcschemes/xcschememanagement.plist
index e922244c..8a89ed79 100644
--- a/Examples/VideoPlayer/node_modules/react-native-video/RCTVideo.xcodeproj/xcuserdata/brentvatne.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/Examples/VideoPlayer/node_modules/react-native-video/RCTVideo.xcodeproj/xcuserdata/brentvatne.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -7,7 +7,7 @@
RCTVideo.xcscheme
orderHint
- 10
+ 12
SuppressBuildableAutocreation
diff --git a/Examples/VideoPlayer/package.json b/Examples/VideoPlayer/package.json
index f76b7cea..1f661e22 100644
--- a/Examples/VideoPlayer/package.json
+++ b/Examples/VideoPlayer/package.json
@@ -6,7 +6,7 @@
"start": "node_modules/react-native/packager/packager.sh"
},
"dependencies": {
- "react-native": "^0.4.0",
- "react-native-video": "^0.3.5"
+ "react-native": "^0.4.4",
+ "react-native-video": "^0.4.1"
}
}
diff --git a/RCTVideo.m b/RCTVideo.m
index be64ea4b..b1484d10 100644
--- a/RCTVideo.m
+++ b/RCTVideo.m
@@ -18,6 +18,7 @@ static NSString *const statusKeyPath = @"status";
{
AVPlayer *_player;
AVPlayerItem *_playerItem;
+ BOOL _playerItemObserverSet;
AVPlayerLayer *_playerLayer;
NSURL *_videoURL;
@@ -87,18 +88,36 @@ static NSString *const statusKeyPath = @"status";
[_progressUpdateTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
-- (void)notifyEnd: (NSNotification *)notification {
+- (void)notifyEnd:(NSNotification *)notification
+{
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{
@"target": self.reactTag
}];
}
+- (void)addPlayerItemObserver
+{
+ [_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
+ _playerItemObserverSet = YES;
+}
+
+/* Fixes https://github.com/brentvatne/react-native-video/issues/43
+ * Crashes caused when trying to remove the observer when there is no
+ * observer set */
+- (void)removePlayerItemObserver
+{
+ if (_playerItemObserverSet) {
+ [_playerItem removeObserver:self forKeyPath:statusKeyPath];
+ _playerItemObserverSet = NO;
+ }
+}
+
#pragma mark - Player and source
- (void)setSrc:(NSDictionary *)source {
- [_playerItem removeObserver:self forKeyPath:statusKeyPath];
+ [self removePlayerItemObserver];
_playerItem = [self playerItemForSource:source];
- [_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
+ [self addPlayerItemObserver];
[_player pause];
[_playerLayer removeFromSuperlayer];
@@ -321,7 +340,7 @@ static NSString *const statusKeyPath = @"status";
[_playerLayer removeFromSuperlayer];
_playerLayer = nil;
- [_playerItem removeObserver:self forKeyPath:statusKeyPath];
+ [self removePlayerItemObserver];
_eventDispatcher = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
diff --git a/package.json b/package.json
index b625d3fa..50f2bd3b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-video",
- "version": "0.4.0",
+ "version": "0.4.1",
"description": "A element for react-native",
"main": "Video.ios.js",
"author": "Brent Vatne (https://github.com/brentvatne)",