Added fullscreen options for iOS Player
This commit is contained in:
parent
0c03932ada
commit
f41831ceac
5
Video.js
5
Video.js
@ -289,6 +289,11 @@ Video.propTypes = {
|
||||
PropTypes.object
|
||||
]),
|
||||
fullscreen: PropTypes.bool,
|
||||
fullscreenOptions: PropTypes.shape({
|
||||
enabled: PropTypes.bool,
|
||||
preferredOrientation: PropTypes.string,
|
||||
autorotate: PropTypes.bool
|
||||
}),
|
||||
onVideoLoadStart: PropTypes.func,
|
||||
onVideoLoad: PropTypes.func,
|
||||
onVideoBuffer: PropTypes.func,
|
||||
|
@ -56,6 +56,7 @@ static int const RCTVideoUnset = -1;
|
||||
NSString * _ignoreSilentSwitch;
|
||||
NSString * _resizeMode;
|
||||
BOOL _fullscreen;
|
||||
NSDictionary* _fullscreenOptions;
|
||||
BOOL _fullscreenPlayerPresented;
|
||||
UIViewController * _presentingViewController;
|
||||
}
|
||||
@ -106,9 +107,16 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
|
||||
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem {
|
||||
|
||||
RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init];
|
||||
playerLayer.showsPlaybackControls = YES;
|
||||
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.player = player;
|
||||
playerLayer.view.frame = self.bounds;
|
||||
@ -331,7 +339,7 @@ static int const RCTVideoUnset = -1;
|
||||
|
||||
[self addPlayerTimeObserver];
|
||||
|
||||
[self setFullscreen:_fullscreen];
|
||||
[self setFullscreenOptions:_fullscreenOptions];
|
||||
|
||||
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
||||
if(self.onVideoLoadStart) {
|
||||
@ -995,10 +1003,34 @@ static int const RCTVideoUnset = -1;
|
||||
return _fullscreenPlayerPresented;
|
||||
}
|
||||
|
||||
- (void)setFullscreen:(BOOL)fullscreen
|
||||
{
|
||||
- (void)setFullscreen:(BOOL) 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 )
|
||||
@ -1027,14 +1059,14 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
[viewController presentViewController:_playerViewController animated:true completion:^{
|
||||
_playerViewController.showsPlaybackControls = YES;
|
||||
_fullscreenPlayerPresented = fullscreen;
|
||||
_fullscreenPlayerPresented = fullscreenEnabled;
|
||||
if(self.onVideoFullscreenPlayerDidPresent) {
|
||||
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
else if ( !fullscreen && _fullscreenPlayerPresented )
|
||||
else if ( !fullscreenEnabled && _fullscreenPlayerPresented )
|
||||
{
|
||||
[self videoPlayerViewControllerWillDismiss:_playerViewController];
|
||||
[_presentingViewController dismissViewControllerAnimated:true completion:^{
|
||||
|
@ -36,7 +36,8 @@ RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(rate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
|
||||
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);
|
||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);
|
||||
|
@ -12,4 +12,9 @@
|
||||
|
||||
@interface RCTVideoPlayerViewController : AVPlayerViewController
|
||||
@property (nonatomic, weak) id<RCTVideoPlayerViewControllerDelegate> rctDelegate;
|
||||
|
||||
// Optional paramters
|
||||
@property (nonatomic, weak) NSString* preferredOrientation;
|
||||
@property (nonatomic) BOOL autorotate;
|
||||
|
||||
@end
|
||||
|
@ -6,6 +6,14 @@
|
||||
|
||||
@implementation RCTVideoPlayerViewController
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.autorotate = false;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
@ -14,17 +22,25 @@
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate {
|
||||
return YES;
|
||||
return self.autorotate;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
||||
|
||||
return UIInterfaceOrientationMaskLandscape;
|
||||
return UIInterfaceOrientationMaskAll;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
|
||||
|
||||
if ([self.preferredOrientation.lowercaseString isEqualToString:@"landscape"]) {
|
||||
return UIInterfaceOrientationLandscapeLeft;
|
||||
}
|
||||
else if ([self.preferredOrientation.lowercaseString isEqualToString:@"portrait"]) {
|
||||
return UIInterfaceOrientationPortrait;
|
||||
}
|
||||
else { // default case
|
||||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user