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 = {
|
Video.propTypes = {
|
||||||
|
filter: PropTypes.oneOf(Video.filterTypes),
|
||||||
/* Native only */
|
/* Native only */
|
||||||
src: PropTypes.object,
|
src: PropTypes.object,
|
||||||
seek: PropTypes.oneOfType([
|
seek: PropTypes.oneOfType([
|
||||||
|
@ -13,6 +13,7 @@ static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
|||||||
static NSString *const playbackRate = @"rate";
|
static NSString *const playbackRate = @"rate";
|
||||||
static NSString *const timedMetadata = @"timedMetadata";
|
static NSString *const timedMetadata = @"timedMetadata";
|
||||||
static NSString *const externalPlaybackActive = @"externalPlaybackActive";
|
static NSString *const externalPlaybackActive = @"externalPlaybackActive";
|
||||||
|
static NSDictionary* filters = nil;
|
||||||
|
|
||||||
static int const RCTVideoUnset = -1;
|
static int const RCTVideoUnset = -1;
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ static int const RCTVideoUnset = -1;
|
|||||||
BOOL _playWhenInactive;
|
BOOL _playWhenInactive;
|
||||||
NSString * _ignoreSilentSwitch;
|
NSString * _ignoreSilentSwitch;
|
||||||
NSString * _resizeMode;
|
NSString * _resizeMode;
|
||||||
|
NSString * _filter;
|
||||||
BOOL _fullscreen;
|
BOOL _fullscreen;
|
||||||
NSString * _fullscreenOrientation;
|
NSString * _fullscreenOrientation;
|
||||||
BOOL _fullscreenPlayerPresented;
|
BOOL _fullscreenPlayerPresented;
|
||||||
@ -75,6 +77,16 @@ static int const RCTVideoUnset = -1;
|
|||||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
|
||||||
{
|
{
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
|
|
||||||
|
filters = @{
|
||||||
|
@"Normal": @"",
|
||||||
|
@"Country": @"CISepiaTone",
|
||||||
|
@"Winter": @"CIPhotoEffectProcess",
|
||||||
|
@"Black N White": @"CIPhotoEffectNoir",
|
||||||
|
@"Sunrise": @"CIPhotoEffectTransfer",
|
||||||
|
@"Artistic": @"CIColorPosterize",
|
||||||
|
};
|
||||||
|
|
||||||
_eventDispatcher = eventDispatcher;
|
_eventDispatcher = eventDispatcher;
|
||||||
|
|
||||||
_playbackRateObserverRegistered = NO;
|
_playbackRateObserverRegistered = NO;
|
||||||
@ -861,6 +873,7 @@ static int const RCTVideoUnset = -1;
|
|||||||
[self setResizeMode:_resizeMode];
|
[self setResizeMode:_resizeMode];
|
||||||
[self setRepeat:_repeat];
|
[self setRepeat:_repeat];
|
||||||
[self setPaused:_paused];
|
[self setPaused:_paused];
|
||||||
|
[self setFilter:_filter];
|
||||||
[self setControls:_controls];
|
[self setControls:_controls];
|
||||||
[self setAllowsExternalPlayback:_allowsExternalPlayback];
|
[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 {
|
- (void)setFullscreenOrientation:(NSString *)orientation {
|
||||||
_fullscreenOrientation = orientation;
|
_fullscreenOrientation = orientation;
|
||||||
if (_fullscreenPlayerPresented) {
|
if (_fullscreenPlayerPresented) {
|
||||||
|
@ -38,6 +38,7 @@ 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);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
|
||||||
|
RCT_EXPORT_VIEW_PROPERTY(filter, NSString);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user