From 449b97a6c283223fe11dcaae7b1b0d3009258928 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Fri, 26 Jun 2015 14:31:03 -0700 Subject: [PATCH 1/6] Fix setPaused threading Fixes #66 --- RCTVideo.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 5b6b425f..af4e5a4a 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -294,10 +294,14 @@ static NSString *const statusKeyPath = @"status"; { if (paused) { [self stopProgressTimer]; - [_player pause]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_player pause]; + }); } else { [self startProgressTimer]; - [_player play]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_player play]; + }); } _paused = paused; From f83da614cfd73e59098f3bb88613f506ece028e3 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Fri, 26 Jun 2015 15:09:10 -0700 Subject: [PATCH 2/6] Seek to time on main thread --- RCTVideo.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index af4e5a4a..00ea810a 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -321,13 +321,15 @@ static NSString *const statusKeyPath = @"status"; CMTime tolerance = CMTimeMake(1000, timeScale); if (CMTimeCompare(current, cmSeekTime) != 0) { - [_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) { - [_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{ - @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], - @"seekTime": [NSNumber numberWithFloat:seekTime], - @"target": self.reactTag + dispatch_async(dispatch_get_main_queue(), ^{ + [_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) { + [_eventDispatcher sendInputEventWithName:RNVideoEventSeek body:@{ + @"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)], + @"seekTime": [NSNumber numberWithFloat:seekTime], + @"target": self.reactTag + }]; }]; - }]; + }); _pendingSeek = false; } From bcecb6ed8116280be2ec2eeef3ecb5f417cef86a Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Fri, 26 Jun 2015 15:12:09 -0700 Subject: [PATCH 3/6] Set video gravity on main thread --- RCTVideo.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RCTVideo.m b/RCTVideo.m index 00ea810a..1ff98250 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -287,7 +287,9 @@ static NSString *const statusKeyPath = @"status"; - (void)setResizeMode:(NSString*)mode { _resizeMode = mode; - _playerLayer.videoGravity = mode; + dispatch_async(dispatch_get_main_queue(), ^{ + _playerLayer.videoGravity = mode; + }); } - (void)setPaused:(BOOL)paused From c985957dd52dfebc76ae7e8eab847a465fe0c09f Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Fri, 26 Jun 2015 15:12:33 -0700 Subject: [PATCH 4/6] Set player rate on main thread --- RCTVideo.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RCTVideo.m b/RCTVideo.m index 1ff98250..f89f649c 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -375,7 +375,9 @@ static NSString *const statusKeyPath = @"status"; [self setResizeMode:_resizeMode]; [self setRepeat:_repeat]; [self setPaused:_paused]; - [_player setRate:_rate]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_player setRate:_rate]; + }); } - (void)setRepeat:(BOOL)repeat { From 3b5319483902669e2bc799b9afcdbe6d1e6106f1 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Fri, 26 Jun 2015 15:13:03 -0700 Subject: [PATCH 5/6] Rename playerItemDidEnd as playerItemDidReachEnd --- RCTVideo.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index f89f649c..668d8ca0 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -264,13 +264,13 @@ static NSString *const statusKeyPath = @"status"; dispatch_async(dispatch_get_main_queue(), ^{ // listen for end of file [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(playerItemDidEnd:) + selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[_player currentItem]]; }); } -- (void)playerItemDidEnd:(NSNotification *)notification +- (void)playerItemDidReachEnd:(NSNotification *)notification { [_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{ @"target": self.reactTag From e8e3ffec8944e684d08e2052c4f1a25d9baf243e Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Sun, 28 Jun 2015 23:23:31 -0700 Subject: [PATCH 6/6] Set volume and muted properties on main queue --- RCTVideo.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 668d8ca0..e5778d5c 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -365,11 +365,15 @@ static NSString *const statusKeyPath = @"status"; - (void)applyModifiers { if (_muted) { - [_player setVolume:0]; - [_player setMuted:YES]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_player setVolume:0]; + [_player setMuted:YES]; + }); } else { - [_player setVolume:_volume]; - [_player setMuted:NO]; + dispatch_async(dispatch_get_main_queue(), ^{ + [_player setVolume:_volume]; + [_player setMuted:NO]; + }); } [self setResizeMode:_resizeMode];