Split fullscreen options into separate props
This commit is contained in:
parent
5336d4f866
commit
0646dca071
14
README.md
14
README.md
@ -254,7 +254,8 @@ var styles = StyleSheet.create({
|
||||
* [bufferConfig](#bufferconfig)
|
||||
* [controls](#controls)
|
||||
* [fullscreen](#fullscreen)
|
||||
* [fullscreenOptions](#fullscreenOptions)
|
||||
* [fullscreenAutorotate](#fullscreenautorotate)
|
||||
* [fullscreenOrientation](#fullscreenorientation)
|
||||
* [headers](#headers)
|
||||
* [ignoreSilentSwitch](#ignoresilentswitch)
|
||||
* [muted](#muted)
|
||||
@ -346,9 +347,20 @@ Platforms: DOM, iOS
|
||||
|
||||
#### fullscreen
|
||||
Controls whether the player enters fullscreen on play. Use fullscreenOptions for extended behaviour.
|
||||
* **false (default)** - Don't display the video in fullscreen
|
||||
* **true** - Display the video in fullscreen
|
||||
|
||||
Platforms: iOS
|
||||
|
||||
#### fullscreenAutorotate
|
||||
If a preferred [fullscreenOrientation](#fullscreenorientation) is set, causes the video to rotate to that orientation when the video enters fullscreen.
|
||||
|
||||
#### fullscreenOrientation
|
||||
|
||||
* **all (default)** -
|
||||
* **landscape**
|
||||
* **portrait**
|
||||
|
||||
#### fullscreenOptions
|
||||
Controls behaviour of the player entering fullscreen, such as forcing landscape playback on portrait devices
|
||||
|
||||
|
7
Video.js
7
Video.js
@ -282,11 +282,6 @@ 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,
|
||||
@ -359,6 +354,8 @@ Video.propTypes = {
|
||||
controls: PropTypes.bool,
|
||||
audioOnly: PropTypes.bool,
|
||||
currentTime: PropTypes.number,
|
||||
fullscreenAutorotate: PropTypes.bool,
|
||||
fullscreenOrientation: PropTypes.string,
|
||||
progressUpdateInterval: PropTypes.number,
|
||||
useTextureView: PropTypes.bool,
|
||||
onLoadStart: PropTypes.func,
|
||||
|
@ -30,7 +30,7 @@ static int const RCTVideoUnset = -1;
|
||||
BOOL _playerBufferEmpty;
|
||||
AVPlayerLayer *_playerLayer;
|
||||
BOOL _playerLayerObserverSet;
|
||||
AVPlayerViewController *_playerViewController;
|
||||
RCTVideoPlayerViewController *_playerViewController;
|
||||
NSURL *_videoURL;
|
||||
|
||||
/* Required to publish events */
|
||||
@ -64,7 +64,8 @@ static int const RCTVideoUnset = -1;
|
||||
NSString * _ignoreSilentSwitch;
|
||||
NSString * _resizeMode;
|
||||
BOOL _fullscreen;
|
||||
NSDictionary* _fullscreenOptions;
|
||||
BOOL _fullscreenAutorotate;
|
||||
NSString * _fullscreenOrientation;
|
||||
BOOL _fullscreenPlayerPresented;
|
||||
UIViewController * _presentingViewController;
|
||||
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
||||
@ -83,6 +84,8 @@ static int const RCTVideoUnset = -1;
|
||||
_rate = 1.0;
|
||||
_volume = 1.0;
|
||||
_resizeMode = @"AVLayerVideoGravityResizeAspectFill";
|
||||
_fullscreenAutorotate = YES;
|
||||
_fullscreenOrientation = @"default";
|
||||
_pendingSeek = false;
|
||||
_pendingSeekTime = 0.0f;
|
||||
_lastSeekTime = 0.0f;
|
||||
@ -120,21 +123,18 @@ static int const RCTVideoUnset = -1;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem {
|
||||
- (RCTVideoPlayerViewController*)createPlayerViewController:(AVPlayer*)player
|
||||
withPlayerItem:(AVPlayerItem*)playerItem {
|
||||
RCTVideoPlayerViewController* viewController = [[RCTVideoPlayerViewController alloc] init];
|
||||
viewController.showsPlaybackControls = YES;
|
||||
viewController.rctDelegate = self;
|
||||
viewController.autorotate = _fullscreenAutorotate;
|
||||
viewController.preferredOrientation = _fullscreenOrientation;
|
||||
|
||||
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;
|
||||
return playerLayer;
|
||||
viewController.view.frame = self.bounds;
|
||||
viewController.player = player;
|
||||
viewController.view.frame = self.bounds;
|
||||
return viewController;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------
|
||||
@ -361,8 +361,6 @@ static int const RCTVideoUnset = -1;
|
||||
|
||||
[self addPlayerTimeObserver];
|
||||
|
||||
[self setFullscreenOptions:_fullscreenOptions];
|
||||
|
||||
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
||||
if (self.onVideoLoadStart) {
|
||||
id uri = [source objectForKey:@"uri"];
|
||||
@ -380,17 +378,15 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
|
||||
- (NSURL*) urlFilePath:(NSString*) filepath {
|
||||
|
||||
// check if the file exists at the specified location
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath]) {
|
||||
return [NSURL fileURLWithPath:filepath];
|
||||
if ([filepath containsString:@"file://"]) {
|
||||
return [NSURL URLWithString:filepath];
|
||||
}
|
||||
|
||||
// if no file found, check if the file exists in the Document directory
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString* relativeFilePath = [filepath lastPathComponent];
|
||||
// the file may be multiple levels below the documents directory
|
||||
NSArray* fileComponents = [filepath componentsSeparatedByString:@"/Documents/"];
|
||||
NSArray* fileComponents = [filepath componentsSeparatedByString:@"Documents/"];
|
||||
if (fileComponents.count > 1) {
|
||||
relativeFilePath = [fileComponents objectAtIndex:1];
|
||||
}
|
||||
@ -1113,33 +1109,7 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
|
||||
- (void)setFullscreen:(BOOL) fullscreen {
|
||||
_fullscreen = fullscreen;
|
||||
|
||||
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 )
|
||||
if( fullscreen && !_fullscreenPlayerPresented )
|
||||
{
|
||||
// Ensure player view controller is not null
|
||||
if( !_playerViewController )
|
||||
@ -1168,14 +1138,14 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
[viewController presentViewController:_playerViewController animated:true completion:^{
|
||||
_playerViewController.showsPlaybackControls = YES;
|
||||
_fullscreenPlayerPresented = fullscreenEnabled;
|
||||
_fullscreenPlayerPresented = fullscreen;
|
||||
if(self.onVideoFullscreenPlayerDidPresent) {
|
||||
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
else if ( !fullscreenEnabled && _fullscreenPlayerPresented )
|
||||
else if ( !fullscreen && _fullscreenPlayerPresented )
|
||||
{
|
||||
[self videoPlayerViewControllerWillDismiss:_playerViewController];
|
||||
[_presentingViewController dismissViewControllerAnimated:true completion:^{
|
||||
@ -1184,6 +1154,20 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFullscreenAutorotate:(BOOL)autorotate {
|
||||
_fullscreenAutorotate = autorotate;
|
||||
if (_fullscreenPlayerPresented) {
|
||||
_playerViewController.autorotate = autorotate;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFullscreenOrientation:(NSString *)orientation {
|
||||
_fullscreenOrientation = orientation;
|
||||
if (_fullscreenPlayerPresented) {
|
||||
_playerViewController.preferredOrientation = orientation;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)usePlayerViewController
|
||||
{
|
||||
if( _player )
|
||||
|
@ -36,8 +36,9 @@ 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); // deprecated property
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenOptions, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenAutorotate, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float);
|
||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);
|
||||
|
Loading…
Reference in New Issue
Block a user