Commit c5eb6b4f authored by Brent Vatne's avatar Brent Vatne
Browse files

Fix crash from trying to remove observer multiple times

parent ca3e6066
Loading
Loading
Loading
Loading
+1.67 KiB (30.5 KiB)

File changed.

No diff preview for this file type.

+1 −1
Changes for Examples/VideoPlayer/node_modules/react-native-video/RCTVideo.xcodeproj/xcuserdata/brentvatne.xcuserdatad/xcschemes/xcschememanagement.plist: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
		<key>RCTVideo.xcscheme</key>
		<dict>
			<key>orderHint</key>
			<integer>10</integer>
			<integer>12</integer>
		</dict>
	</dict>
	<key>SuppressBuildableAutocreation</key>
+2 −2
Changes for Examples/VideoPlayer/package.json: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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"
  }
}
+23 −4
Changes for RCTVideo.m: 23 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -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];
+1 −1
Changes for package.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
{
  "name": "react-native-video",
  "version": "0.4.0",
  "version": "0.4.1",
  "description": "A <Video /> element for react-native",
  "main": "Video.ios.js",
  "author": "Brent Vatne <brentvatne@gmail.com> (https://github.com/brentvatne)",