added video filter
This commit is contained in:
parent
2c391f5807
commit
18e8895712
3
Video.js
3
Video.js
@ -274,7 +274,10 @@ export default class Video extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
Video.filterTypes = ['Normal', 'Country', 'Winter', 'Black N White', 'Sunrise', 'Artistic'];
|
||||
|
||||
Video.propTypes = {
|
||||
filter: PropTypes.oneOf(Video.filterTypes),
|
||||
/* Native only */
|
||||
src: PropTypes.object,
|
||||
seek: PropTypes.oneOfType([
|
||||
|
@ -13,6 +13,7 @@ static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
||||
static NSString *const playbackRate = @"rate";
|
||||
static NSString *const timedMetadata = @"timedMetadata";
|
||||
static NSString *const externalPlaybackActive = @"externalPlaybackActive";
|
||||
static NSDictionary* filters = nil;
|
||||
|
||||
static int const RCTVideoUnset = -1;
|
||||
|
||||
@ -63,6 +64,7 @@ static int const RCTVideoUnset = -1;
|
||||
BOOL _playWhenInactive;
|
||||
NSString * _ignoreSilentSwitch;
|
||||
NSString * _resizeMode;
|
||||
NSString * _filter;
|
||||
BOOL _fullscreen;
|
||||
NSString * _fullscreenOrientation;
|
||||
BOOL _fullscreenPlayerPresented;
|
||||
@ -75,6 +77,16 @@ static int const RCTVideoUnset = -1;
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
|
||||
filters = @{
|
||||
@"Normal": @"",
|
||||
@"Country": @"CISepiaTone",
|
||||
@"Winter": @"CIPhotoEffectProcess",
|
||||
@"Black N White": @"CIPhotoEffectNoir",
|
||||
@"Sunrise": @"CIPhotoEffectTransfer",
|
||||
@"Artistic": @"CIColorPosterize",
|
||||
};
|
||||
|
||||
_eventDispatcher = eventDispatcher;
|
||||
|
||||
_playbackRateObserverRegistered = NO;
|
||||
@ -861,6 +873,7 @@ static int const RCTVideoUnset = -1;
|
||||
[self setResizeMode:_resizeMode];
|
||||
[self setRepeat:_repeat];
|
||||
[self setPaused:_paused];
|
||||
[self setFilter:_filter];
|
||||
[self setControls:_controls];
|
||||
[self setAllowsExternalPlayback:_allowsExternalPlayback];
|
||||
}
|
||||
@ -1151,6 +1164,43 @@ static int const RCTVideoUnset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFilter:(NSString *)filter {
|
||||
|
||||
_filter = filter;
|
||||
|
||||
AVAsset *asset = _playerItem.asset;
|
||||
|
||||
if (asset != nil) {
|
||||
|
||||
NSString *filterName = filters[filter];
|
||||
CIFilter *filter = [CIFilter filterWithName:filterName];
|
||||
|
||||
_playerItem.videoComposition = [AVVideoComposition
|
||||
videoCompositionWithAsset:asset
|
||||
applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest *_Nonnull request) {
|
||||
|
||||
if (filter == nil) {
|
||||
|
||||
[request finishWithImage:request.sourceImage context:nil];
|
||||
|
||||
} else {
|
||||
|
||||
CIImage *image = request.sourceImage.imageByClampingToExtent;
|
||||
|
||||
[filter setValue:image forKey:kCIInputImageKey];
|
||||
|
||||
CIImage *output = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent];
|
||||
|
||||
[request finishWithImage:output context:nil];
|
||||
|
||||
}
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)setFullscreenOrientation:(NSString *)orientation {
|
||||
_fullscreenOrientation = orientation;
|
||||
if (_fullscreenPlayerPresented) {
|
||||
|
@ -38,6 +38,7 @@ RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(currentTime, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(filter, 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