Merge pull request #70 from brentvatne/fix/player-access

Fix issues that arise due to accessing _player on a queue other than main
This commit is contained in:
Baris Sencan 2015-07-01 14:16:59 -07:00
commit dae2ea2f66

View File

@ -264,13 +264,13 @@ static NSString *const statusKeyPath = @"status";
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
// listen for end of file // listen for end of file
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidEnd:) selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification name:AVPlayerItemDidPlayToEndTimeNotification
object:[_player currentItem]]; object:[_player currentItem]];
}); });
} }
- (void)playerItemDidEnd:(NSNotification *)notification - (void)playerItemDidReachEnd:(NSNotification *)notification
{ {
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{ [_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{
@"target": self.reactTag @"target": self.reactTag
@ -287,17 +287,23 @@ static NSString *const statusKeyPath = @"status";
- (void)setResizeMode:(NSString*)mode - (void)setResizeMode:(NSString*)mode
{ {
_resizeMode = mode; _resizeMode = mode;
_playerLayer.videoGravity = mode; dispatch_async(dispatch_get_main_queue(), ^{
_playerLayer.videoGravity = mode;
});
} }
- (void)setPaused:(BOOL)paused - (void)setPaused:(BOOL)paused
{ {
if (paused) { if (paused) {
[self stopProgressTimer]; [self stopProgressTimer];
[_player pause]; dispatch_async(dispatch_get_main_queue(), ^{
[_player pause];
});
} else { } else {
[self startProgressTimer]; [self startProgressTimer];
[_player play]; dispatch_async(dispatch_get_main_queue(), ^{
[_player play];
});
} }
_paused = paused; _paused = paused;
@ -317,13 +323,15 @@ static NSString *const statusKeyPath = @"status";
CMTime tolerance = CMTimeMake(1000, timeScale); CMTime tolerance = CMTimeMake(1000, timeScale);
if (CMTimeCompare(current, cmSeekTime) != 0) { if (CMTimeCompare(current, cmSeekTime) != 0) {
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) { dispatch_async(dispatch_get_main_queue(), ^{
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{ [_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], [_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{
@"seekTime": [NSNumber numberWithFloat:seekTime], @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
@"target": self.reactTag @"seekTime": [NSNumber numberWithFloat:seekTime],
@"target": self.reactTag
}];
}]; }];
}]; });
_pendingSeek = false; _pendingSeek = false;
} }
@ -357,17 +365,23 @@ static NSString *const statusKeyPath = @"status";
- (void)applyModifiers - (void)applyModifiers
{ {
if (_muted) { if (_muted) {
[_player setVolume:0]; dispatch_async(dispatch_get_main_queue(), ^{
[_player setMuted:YES]; [_player setVolume:0];
[_player setMuted:YES];
});
} else { } else {
[_player setVolume:_volume]; dispatch_async(dispatch_get_main_queue(), ^{
[_player setMuted:NO]; [_player setVolume:_volume];
[_player setMuted:NO];
});
} }
[self setResizeMode:_resizeMode]; [self setResizeMode:_resizeMode];
[self setRepeat:_repeat]; [self setRepeat:_repeat];
[self setPaused:_paused]; [self setPaused:_paused];
[_player setRate:_rate]; dispatch_async(dispatch_get_main_queue(), ^{
[_player setRate:_rate];
});
} }
- (void)setRepeat:(BOOL)repeat { - (void)setRepeat:(BOOL)repeat {