Address some of the feedback from the pull reqeust
This commit is contained in:
committed by
Abdulrahman Alzenki
parent
4a16151195
commit
62dc913cb3
@@ -38,8 +38,8 @@
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackResume;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackRateChange;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoExternalPlaybackChange;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onIsPictureInPictureSupported;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onIsPictureInPictureActive;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPictureInPictureStatusChanged;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onRestoreUserInterfaceForPictureInPictureStop;
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
@@ -66,6 +66,7 @@ static int const RCTVideoUnset = -1;
|
||||
BOOL _playbackStalled;
|
||||
BOOL _playInBackground;
|
||||
BOOL _playWhenInactive;
|
||||
BOOL _pictureInPicture;
|
||||
NSString * _ignoreSilentSwitch;
|
||||
NSString * _resizeMode;
|
||||
BOOL _fullscreen;
|
||||
@@ -102,6 +103,7 @@ static int const RCTVideoUnset = -1;
|
||||
_playInBackground = false;
|
||||
_allowsExternalPlayback = YES;
|
||||
_playWhenInactive = false;
|
||||
_pictureInPicture = false;
|
||||
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
|
||||
_restoreUserInterfaceForPIPStopCompletionHandler = NULL;
|
||||
#if __has_include(<react-native-video/RCTVideoCache.h>)
|
||||
@@ -382,12 +384,6 @@ static int const RCTVideoUnset = -1;
|
||||
@"target": self.reactTag
|
||||
});
|
||||
}
|
||||
|
||||
if (@available(iOS 9, *)) {
|
||||
if (self.onIsPictureInPictureSupported) {
|
||||
self.onIsPictureInPictureSupported(@{@"supported": [NSNumber numberWithBool:(bool)[AVPictureInPictureController isPictureInPictureSupported]]});
|
||||
}
|
||||
}
|
||||
}];
|
||||
});
|
||||
_videoLoadStarted = YES;
|
||||
@@ -791,11 +787,16 @@ static int const RCTVideoUnset = -1;
|
||||
|
||||
- (void)setPictureInPicture:(BOOL)pictureInPicture
|
||||
{
|
||||
if (_pipController && pictureInPicture && ![_pipController isPictureInPictureActive]) {
|
||||
if (_pictureInPicture == pictureInPicture) {
|
||||
return;
|
||||
}
|
||||
|
||||
_pictureInPicture = pictureInPicture;
|
||||
if (_pipController && _pictureInPicture && ![_pipController isPictureInPictureActive]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_pipController startPictureInPicture];
|
||||
});
|
||||
} else if (_pipController && !pictureInPicture && [_pipController isPictureInPictureActive]) {
|
||||
} else if (_pipController && !_pictureInPicture && [_pipController isPictureInPictureActive]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_pipController stopPictureInPicture];
|
||||
});
|
||||
@@ -811,12 +812,10 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
|
||||
- (void)setupPipController {
|
||||
if (@available(iOS 9, *)) {
|
||||
if (!_pipController && _playerLayer && [AVPictureInPictureController isPictureInPictureSupported]) {
|
||||
// Create new controller passing reference to the AVPlayerLayer
|
||||
_pipController = [[AVPictureInPictureController alloc] initWithPlayerLayer:_playerLayer];
|
||||
_pipController.delegate = self;
|
||||
}
|
||||
if (!_pipController && _playerLayer && [AVPictureInPictureController isPictureInPictureSupported]) {
|
||||
// Create new controller passing reference to the AVPlayerLayer
|
||||
_pipController = [[AVPictureInPictureController alloc] initWithPlayerLayer:_playerLayer];
|
||||
_pipController.delegate = self;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1535,14 +1534,18 @@ static int const RCTVideoUnset = -1;
|
||||
#pragma mark - Picture in Picture
|
||||
|
||||
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
||||
if (self.onIsPictureInPictureActive && _pipController) {
|
||||
self.onIsPictureInPictureActive(@{@"active": [NSNumber numberWithBool:false]});
|
||||
if (self.onPictureInPictureStatusChanged) {
|
||||
self.onPictureInPictureStatusChanged(@{
|
||||
@"isActive": [NSNumber numberWithBool:false]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
||||
if (self.onIsPictureInPictureActive && _pipController) {
|
||||
self.onIsPictureInPictureActive(@{@"active": [NSNumber numberWithBool:true]});
|
||||
if (self.onPictureInPictureStatusChanged) {
|
||||
self.onPictureInPictureStatusChanged(@{
|
||||
@"isActive": [NSNumber numberWithBool:true]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1560,6 +1563,9 @@ static int const RCTVideoUnset = -1;
|
||||
|
||||
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL))completionHandler {
|
||||
NSAssert(_restoreUserInterfaceForPIPStopCompletionHandler == NULL, @"restoreUserInterfaceForPIPStopCompletionHandler was not called after picture in picture was exited.");
|
||||
if (self.onRestoreUserInterfaceForPictureInPictureStop) {
|
||||
self.onRestoreUserInterfaceForPictureInPictureStop(@{});
|
||||
}
|
||||
_restoreUserInterfaceForPIPStopCompletionHandler = completionHandler;
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,7 @@ RCT_EXPORT_VIEW_PROPERTY(controls, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(volume, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(pictureInPicture, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(rate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
|
||||
@@ -42,7 +43,6 @@ RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(filter, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(filterEnabled, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(pictureInPicture, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(restoreUserInterfaceForPIPStopCompletionHandler, BOOL);
|
||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);
|
||||
@@ -79,8 +79,8 @@ RCT_REMAP_METHOD(save,
|
||||
}
|
||||
}];
|
||||
}
|
||||
RCT_EXPORT_VIEW_PROPERTY(onIsPictureInPictureSupported, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onIsPictureInPictureActive, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureStatusChanged, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onRestoreUserInterfaceForPictureInPictureStop, RCTBubblingEventBlock);
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
|
Reference in New Issue
Block a user