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:
commit
dae2ea2f66
18
RCTVideo.m
18
RCTVideo.m
@ -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;
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
_playerLayer.videoGravity = mode;
|
_playerLayer.videoGravity = mode;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPaused:(BOOL)paused
|
- (void)setPaused:(BOOL)paused
|
||||||
{
|
{
|
||||||
if (paused) {
|
if (paused) {
|
||||||
[self stopProgressTimer];
|
[self stopProgressTimer];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player pause];
|
[_player pause];
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
[self startProgressTimer];
|
[self startProgressTimer];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player play];
|
[_player play];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_paused = paused;
|
_paused = paused;
|
||||||
@ -317,6 +323,7 @@ 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) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{
|
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{
|
||||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
||||||
@ -324,6 +331,7 @@ static NSString *const statusKeyPath = @"status";
|
|||||||
@"target": self.reactTag
|
@"target": self.reactTag
|
||||||
}];
|
}];
|
||||||
}];
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
_pendingSeek = false;
|
_pendingSeek = false;
|
||||||
}
|
}
|
||||||
@ -357,17 +365,23 @@ static NSString *const statusKeyPath = @"status";
|
|||||||
- (void)applyModifiers
|
- (void)applyModifiers
|
||||||
{
|
{
|
||||||
if (_muted) {
|
if (_muted) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player setVolume:0];
|
[_player setVolume:0];
|
||||||
[_player setMuted:YES];
|
[_player setMuted:YES];
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player setVolume:_volume];
|
[_player setVolume:_volume];
|
||||||
[_player setMuted:NO];
|
[_player setMuted:NO];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setResizeMode:_resizeMode];
|
[self setResizeMode:_resizeMode];
|
||||||
[self setRepeat:_repeat];
|
[self setRepeat:_repeat];
|
||||||
[self setPaused:_paused];
|
[self setPaused:_paused];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_player setRate:_rate];
|
[_player setRate:_rate];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRepeat:(BOOL)repeat {
|
- (void)setRepeat:(BOOL)repeat {
|
||||||
|
Loading…
Reference in New Issue
Block a user