Added fullscreen options for iOS Player
This commit is contained in:
		
							
								
								
									
										5
									
								
								Video.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Video.js
									
									
									
									
									
								
							| @@ -289,6 +289,11 @@ Video.propTypes = { | |||||||
|     PropTypes.object |     PropTypes.object | ||||||
|   ]), |   ]), | ||||||
|   fullscreen: PropTypes.bool, |   fullscreen: PropTypes.bool, | ||||||
|  |   fullscreenOptions: PropTypes.shape({ | ||||||
|  |     enabled: PropTypes.bool, | ||||||
|  |     preferredOrientation: PropTypes.string, | ||||||
|  |     autorotate: PropTypes.bool | ||||||
|  |   }), | ||||||
|   onVideoLoadStart: PropTypes.func, |   onVideoLoadStart: PropTypes.func, | ||||||
|   onVideoLoad: PropTypes.func, |   onVideoLoad: PropTypes.func, | ||||||
|   onVideoBuffer: PropTypes.func, |   onVideoBuffer: PropTypes.func, | ||||||
|   | |||||||
| @@ -62,6 +62,7 @@ static int const RCTVideoUnset = -1; | |||||||
|   NSString * _ignoreSilentSwitch; |   NSString * _ignoreSilentSwitch; | ||||||
|   NSString * _resizeMode; |   NSString * _resizeMode; | ||||||
|   BOOL _fullscreen; |   BOOL _fullscreen; | ||||||
|  |   NSDictionary* _fullscreenOptions; | ||||||
|   BOOL _fullscreenPlayerPresented; |   BOOL _fullscreenPlayerPresented; | ||||||
|   UIViewController * _presentingViewController; |   UIViewController * _presentingViewController; | ||||||
| #if __has_include(<react-native-video/RCTVideoCache.h>) | #if __has_include(<react-native-video/RCTVideoCache.h>) | ||||||
| @@ -117,9 +118,16 @@ static int const RCTVideoUnset = -1; | |||||||
| } | } | ||||||
|  |  | ||||||
| - (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem { | - (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem { | ||||||
|  |    | ||||||
|   RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init]; |   RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init]; | ||||||
|   playerLayer.showsPlaybackControls = YES; |   playerLayer.showsPlaybackControls = YES; | ||||||
|   playerLayer.rctDelegate = self; |   playerLayer.rctDelegate = self; | ||||||
|  |    | ||||||
|  |   if (_fullscreenOptions) { | ||||||
|  |     playerLayer.preferredOrientation = [RCTConvert NSString:[_fullscreenOptions objectForKey:@"preferredOrientation"]]; | ||||||
|  |     playerLayer.autorotate = [RCTConvert BOOL:[_fullscreenOptions objectForKey:@"autorotate"]]; | ||||||
|  |   } | ||||||
|  |    | ||||||
|   playerLayer.view.frame = self.bounds; |   playerLayer.view.frame = self.bounds; | ||||||
|   playerLayer.player = player; |   playerLayer.player = player; | ||||||
|   playerLayer.view.frame = self.bounds; |   playerLayer.view.frame = self.bounds; | ||||||
| @@ -343,7 +351,7 @@ static int const RCTVideoUnset = -1; | |||||||
|          |          | ||||||
|       [self addPlayerTimeObserver]; |       [self addPlayerTimeObserver]; | ||||||
|  |  | ||||||
|       [self setFullscreen:_fullscreen]; |       [self setFullscreenOptions:_fullscreenOptions]; | ||||||
|          |          | ||||||
|       //Perform on next run loop, otherwise onVideoLoadStart is nil |       //Perform on next run loop, otherwise onVideoLoadStart is nil | ||||||
|       if (self.onVideoLoadStart) { |       if (self.onVideoLoadStart) { | ||||||
| @@ -1086,10 +1094,37 @@ static int const RCTVideoUnset = -1; | |||||||
|   return _fullscreenPlayerPresented; |   return _fullscreenPlayerPresented; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (void)setFullscreen:(BOOL)fullscreen | - (void)setFullscreen:(BOOL) fullscreen { | ||||||
| { |  | ||||||
|   _fullscreen = fullscreen; |   _fullscreen = fullscreen; | ||||||
|   if( fullscreen && !_fullscreenPlayerPresented && _player ) |    | ||||||
|  |   NSString* enabled = _fullscreen ? @"1" : @"0"; | ||||||
|  |    | ||||||
|  |   if (!_fullscreenOptions) { | ||||||
|  |     [self setFullscreenOptions: | ||||||
|  |       @{ | ||||||
|  |         @"enabled": enabled, | ||||||
|  |         @"autorotate": @"0", | ||||||
|  |         @"preferredOrientation": @"default" | ||||||
|  |         }]; | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     [_fullscreenOptions setValue:enabled forKey:@"enabled"]; | ||||||
|  |     [self setFullscreenOptions:_fullscreenOptions]; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | - (void)setFullscreenOptions:(NSDictionary*) fullscreenOptions | ||||||
|  | { | ||||||
|  |   _fullscreenOptions = fullscreenOptions; | ||||||
|  |    | ||||||
|  |   if (!_fullscreenOptions) return; | ||||||
|  |    | ||||||
|  |   BOOL fullscreenEnabled = [RCTConvert BOOL:[_fullscreenOptions objectForKey:@"enabled"]]; | ||||||
|  |    | ||||||
|  |   if( fullscreenEnabled && !_fullscreenPlayerPresented && _player ) | ||||||
|  |   { | ||||||
|  |     // Ensure player view controller is not null | ||||||
|  |     if( !_playerViewController ) | ||||||
|     { |     { | ||||||
|       [self usePlayerViewController]; |       [self usePlayerViewController]; | ||||||
|     } |     } | ||||||
| @@ -1115,14 +1150,14 @@ static int const RCTVideoUnset = -1; | |||||||
|       } |       } | ||||||
|       [viewController presentViewController:_playerViewController animated:true completion:^{ |       [viewController presentViewController:_playerViewController animated:true completion:^{ | ||||||
|         _playerViewController.showsPlaybackControls = YES; |         _playerViewController.showsPlaybackControls = YES; | ||||||
|         _fullscreenPlayerPresented = fullscreen; |         _fullscreenPlayerPresented = fullscreenEnabled; | ||||||
|         if(self.onVideoFullscreenPlayerDidPresent) { |         if(self.onVideoFullscreenPlayerDidPresent) { | ||||||
|           self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag}); |           self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag}); | ||||||
|         } |         } | ||||||
|       }]; |       }]; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   else if ( !fullscreen && _fullscreenPlayerPresented ) |   else if ( !fullscreenEnabled && _fullscreenPlayerPresented ) | ||||||
|   { |   { | ||||||
|     [self videoPlayerViewControllerWillDismiss:_playerViewController]; |     [self videoPlayerViewControllerWillDismiss:_playerViewController]; | ||||||
|     [_presentingViewController dismissViewControllerAnimated:true completion:^{ |     [_presentingViewController dismissViewControllerAnimated:true completion:^{ | ||||||
|   | |||||||
| @@ -36,7 +36,8 @@ RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString); | |||||||
| RCT_EXPORT_VIEW_PROPERTY(rate, float); | RCT_EXPORT_VIEW_PROPERTY(rate, float); | ||||||
| RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); | RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); | ||||||
| RCT_EXPORT_VIEW_PROPERTY(currentTime, float); | RCT_EXPORT_VIEW_PROPERTY(currentTime, float); | ||||||
| RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL); | RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);  // deprecated property | ||||||
|  | RCT_EXPORT_VIEW_PROPERTY(fullscreenOptions, NSDictionary); | ||||||
| RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float); | RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float); | ||||||
| /* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */ | /* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */ | ||||||
| RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock); | RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock); | ||||||
|   | |||||||
| @@ -12,4 +12,9 @@ | |||||||
|  |  | ||||||
| @interface RCTVideoPlayerViewController : AVPlayerViewController | @interface RCTVideoPlayerViewController : AVPlayerViewController | ||||||
| @property (nonatomic, weak) id<RCTVideoPlayerViewControllerDelegate> rctDelegate; | @property (nonatomic, weak) id<RCTVideoPlayerViewControllerDelegate> rctDelegate; | ||||||
|  |  | ||||||
|  | // Optional paramters | ||||||
|  | @property (nonatomic, weak) NSString* preferredOrientation; | ||||||
|  | @property (nonatomic) BOOL autorotate; | ||||||
|  |  | ||||||
| @end | @end | ||||||
|   | |||||||
| @@ -6,6 +6,14 @@ | |||||||
|  |  | ||||||
| @implementation RCTVideoPlayerViewController | @implementation RCTVideoPlayerViewController | ||||||
|  |  | ||||||
|  | - (id)init { | ||||||
|  |   self = [super init]; | ||||||
|  |   if (self) { | ||||||
|  |     self.autorotate = false; | ||||||
|  |   } | ||||||
|  |   return self; | ||||||
|  | } | ||||||
|  |  | ||||||
| - (void)viewDidDisappear:(BOOL)animated | - (void)viewDidDisappear:(BOOL)animated | ||||||
| { | { | ||||||
|   [super viewDidDisappear:animated]; |   [super viewDidDisappear:animated]; | ||||||
| @@ -14,17 +22,25 @@ | |||||||
| } | } | ||||||
|  |  | ||||||
| - (BOOL)shouldAutorotate { | - (BOOL)shouldAutorotate { | ||||||
|   return YES; |   return self.autorotate; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (UIInterfaceOrientationMask)supportedInterfaceOrientations { | - (UIInterfaceOrientationMask)supportedInterfaceOrientations { | ||||||
|    |    | ||||||
|   return UIInterfaceOrientationMaskLandscape; |   return UIInterfaceOrientationMaskAll; | ||||||
| } | } | ||||||
|  |  | ||||||
| - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { | - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { | ||||||
|    |   if ([self.preferredOrientation.lowercaseString isEqualToString:@"landscape"]) { | ||||||
|     return UIInterfaceOrientationLandscapeLeft; |     return UIInterfaceOrientationLandscapeLeft; | ||||||
|  |   } | ||||||
|  |   else if ([self.preferredOrientation.lowercaseString isEqualToString:@"portrait"]) { | ||||||
|  |     return UIInterfaceOrientationPortrait; | ||||||
|  |   } | ||||||
|  |   else { // default case | ||||||
|  |     UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; | ||||||
|  |     return orientation; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @end | @end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user