react-native-video-trim 5.0.4 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +0,0 @@
1
- #import "AssetLoader.h"
2
-
3
- @interface AssetLoader ()
4
- @property (nonatomic, strong) AVURLAsset *asset;
5
- @end
6
-
7
- @implementation AssetLoader
8
-
9
- - (void)loadAssetWithURL:(NSURL *)url isVideoType:(BOOL)isVideoType {
10
- NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey: @YES };
11
- self.asset = [AVURLAsset URLAssetWithURL:url options:options];
12
- NSArray *keys = @[ @"duration", @"tracks" ];
13
- [self.asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
14
- [self assetLoaded:isVideoType];
15
- }];
16
- }
17
-
18
- - (void)assetLoaded:(BOOL)isVideoType {
19
- NSArray *keys = @[ @"duration", @"tracks" ];
20
- for (NSString *key in keys) {
21
- NSError *error = nil;
22
- AVKeyValueStatus status = [self.asset statusOfValueForKey:key error:&error];
23
- if (status == AVKeyValueStatusFailed) {
24
- if ([self.delegate respondsToSelector:@selector(assetLoader:didFailWithError:forKey:)]) {
25
- [self.delegate assetLoader:self didFailWithError:error forKey:key];
26
- }
27
- return;
28
- } else if (status == AVKeyValueStatusCancelled) {
29
- NSError *cancelError = [NSError errorWithDomain:@"AssetLoader" code:-1 userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"%@ loading was cancelled", key] }];
30
- if ([self.delegate respondsToSelector:@selector(assetLoader:didFailWithError:forKey:)]) {
31
- [self.delegate assetLoader:self didFailWithError:cancelError forKey:key];
32
- }
33
- return;
34
- } else if (status != AVKeyValueStatusLoaded) {
35
- NSError *unknownError = [NSError errorWithDomain:@"AssetLoader" code:-1 userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"%@ is in an unknown state", key] }];
36
- if ([self.delegate respondsToSelector:@selector(assetLoader:didFailWithError:forKey:)]) {
37
- [self.delegate assetLoader:self didFailWithError:unknownError forKey:key];
38
- }
39
- return;
40
- }
41
- }
42
- if (isVideoType) {
43
- [self processAssetTracks];
44
- } else {
45
- if ([self.delegate respondsToSelector:@selector(assetLoaderDidSucceed:)]) {
46
- [self.delegate assetLoaderDidSucceed:self];
47
- }
48
- }
49
- }
50
-
51
- - (void)processAssetTracks {
52
- NSArray *videoTracks = [self.asset tracksWithMediaType:AVMediaTypeVideo];
53
- AVAssetTrack *videoTrack = videoTracks.firstObject;
54
- if (!videoTrack) {
55
- NSError *error = [NSError errorWithDomain:@"AssetLoader" code:-1 userInfo:@{ NSLocalizedDescriptionKey: @"No video tracks found" }];
56
- if ([self.delegate respondsToSelector:@selector(assetLoader:didFailWithError:forKey:)]) {
57
- [self.delegate assetLoader:self didFailWithError:error forKey:@"tracks"];
58
- }
59
- return;
60
- }
61
- NSArray *trackKeys = @[ @"naturalSize", @"preferredTransform" ];
62
- [videoTrack loadValuesAsynchronouslyForKeys:trackKeys completionHandler:^{
63
- [self trackPropertiesLoaded:videoTrack];
64
- }];
65
- }
66
-
67
- - (void)trackPropertiesLoaded:(AVAssetTrack *)track {
68
- NSError *error = nil;
69
- AVKeyValueStatus naturalSizeStatus = [track statusOfValueForKey:@"naturalSize" error:&error];
70
- AVKeyValueStatus preferredTransformStatus = [track statusOfValueForKey:@"preferredTransform" error:&error];
71
- if (naturalSizeStatus == AVKeyValueStatusLoaded && preferredTransformStatus == AVKeyValueStatusLoaded) {
72
- CGSize naturalSize = track.naturalSize;
73
- CGAffineTransform preferredTransform = track.preferredTransform;
74
- NSLog(@"Natural size: %@", NSStringFromCGSize(naturalSize));
75
- NSLog(@"Preferred transform: %@", NSStringFromCGAffineTransform(preferredTransform));
76
- if ([self.delegate respondsToSelector:@selector(assetLoaderDidSucceed:)]) {
77
- [self.delegate assetLoaderDidSucceed:self];
78
- }
79
- } else {
80
- if ([self.delegate respondsToSelector:@selector(assetLoader:didFailWithError:forKey:)]) {
81
- NSString *failedKey = (naturalSizeStatus != AVKeyValueStatusLoaded) ? @"naturalSize" : @"preferredTransform";
82
- [self.delegate assetLoader:self didFailWithError:error forKey:failedKey];
83
- }
84
- }
85
- }
86
-
87
- @end
package/ios/ErrorCode.h DELETED
@@ -1,9 +0,0 @@
1
- // ErrorCode.h
2
- typedef NS_ENUM(NSInteger, ErrorCode) {
3
- ErrorCodeTrimmingFailed,
4
- ErrorCodeFailToLoadMedia,
5
- ErrorCodeFailToSaveToPhoto,
6
- ErrorCodeFailToShare,
7
- ErrorCodeNoPhotoPermission,
8
- ErrorCodeInvalidFilePath
9
- };
@@ -1,12 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
-
3
- @interface ProgressAlertController : UIViewController
4
-
5
- @property (nonatomic, copy) void (^onDismiss)(void);
6
-
7
- - (void)setTitle:(NSString *)text;
8
- - (void)setCancelTitle:(NSString *)text;
9
- - (void)setProgress:(float)progress;
10
- - (void)showCancelBtn;
11
-
12
- @end
@@ -1,106 +0,0 @@
1
- #import "ProgressAlertController.h"
2
-
3
- @interface ProgressAlertController ()
4
-
5
- @property (nonatomic, strong) UILabel *titleLabel;
6
- @property (nonatomic, strong) UIProgressView *progressBar;
7
- @property (nonatomic, strong) UIButton *actionButton;
8
-
9
- @end
10
-
11
- @implementation ProgressAlertController
12
-
13
- - (instancetype)init {
14
- // init early because in VideoTrim.mm we call this before presenting the view controller (before viewDidLoad)
15
- if (self = [super init]) {
16
- self.titleLabel = [[UILabel alloc] init];
17
- self.progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
18
- self.actionButton = [UIButton buttonWithType:UIButtonTypeSystem];
19
- }
20
- return self;
21
- }
22
-
23
- - (void)viewDidLoad {
24
- [super viewDidLoad];
25
- [self setupBackground];
26
- [self setupAlertView];
27
- }
28
-
29
- - (void)setupBackground {
30
- self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
31
- }
32
-
33
- - (void)setupAlertView {
34
- UIView *alertView = [[UIView alloc] init];
35
- alertView.backgroundColor = [UIColor colorWithRed:28.0/255.0 green:28.0/255.0 blue:30.0/255.0 alpha:1.0];
36
- alertView.layer.cornerRadius = 12;
37
- alertView.translatesAutoresizingMaskIntoConstraints = NO;
38
- [self.view addSubview:alertView];
39
-
40
- // AlertView Constraints
41
- [NSLayoutConstraint activateConstraints:@[
42
- [alertView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
43
- [alertView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor],
44
- [alertView.widthAnchor constraintEqualToConstant:270]
45
- ]];
46
-
47
- // Title Label
48
- self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
49
- self.titleLabel.textAlignment = NSTextAlignmentCenter;
50
- self.titleLabel.font = [UIFont systemFontOfSize:18];
51
- self.titleLabel.numberOfLines = 0;
52
- self.titleLabel.textColor = [UIColor whiteColor];
53
- [alertView addSubview:self.titleLabel];
54
-
55
- // Progress Bar
56
- self.progressBar.translatesAutoresizingMaskIntoConstraints = NO;
57
- [alertView addSubview:self.progressBar];
58
-
59
- // Action Button
60
-
61
- [self.actionButton setTitle:@"Cancel" forState:UIControlStateNormal];
62
- [self.actionButton setTitleColor:[UIColor systemPinkColor] forState:UIControlStateNormal];
63
- self.actionButton.titleLabel.font = [UIFont systemFontOfSize:16];
64
- [self.actionButton addTarget:self action:@selector(dismissAlert) forControlEvents:UIControlEventTouchUpInside];
65
- self.actionButton.translatesAutoresizingMaskIntoConstraints = NO;
66
- self.actionButton.hidden = YES;
67
- [alertView addSubview:self.actionButton];
68
-
69
- // Constraints for titleLabel, progressBar, and actionButton
70
- [NSLayoutConstraint activateConstraints:@[
71
- [self.titleLabel.topAnchor constraintEqualToAnchor:alertView.topAnchor constant:16],
72
- [self.titleLabel.leadingAnchor constraintEqualToAnchor:alertView.leadingAnchor constant:16],
73
- [self.titleLabel.trailingAnchor constraintEqualToAnchor:alertView.trailingAnchor constant:-16],
74
-
75
- [self.progressBar.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:16],
76
- [self.progressBar.leadingAnchor constraintEqualToAnchor:alertView.leadingAnchor constant:16],
77
- [self.progressBar.trailingAnchor constraintEqualToAnchor:alertView.trailingAnchor constant:-16],
78
-
79
- [self.actionButton.topAnchor constraintEqualToAnchor:self.progressBar.bottomAnchor constant:16],
80
- [self.actionButton.bottomAnchor constraintEqualToAnchor:alertView.bottomAnchor constant:-16],
81
- [self.actionButton.centerXAnchor constraintEqualToAnchor:alertView.centerXAnchor]
82
- ]];
83
- }
84
-
85
- - (void)dismissAlert {
86
- if (self.onDismiss) self.onDismiss();
87
- }
88
-
89
- - (void)setTitle:(NSString *)text {
90
- self.titleLabel.text = text;
91
- }
92
-
93
- - (void)setCancelTitle:(NSString *)text {
94
- [self.actionButton setTitle:text forState:UIControlStateNormal];
95
- }
96
-
97
- - (void)setProgress:(float)progress {
98
- [self.progressBar setProgress:progress animated:YES];
99
- }
100
-
101
- - (void)showCancelBtn {
102
- [self.view layoutIfNeeded];
103
- self.actionButton.hidden = NO;
104
- }
105
-
106
- @end
@@ -1,67 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
- #import <AVFoundation/AVFoundation.h>
3
-
4
- @class VideoTrimmerThumb;
5
-
6
- typedef NS_ENUM(NSInteger, VideoTrimmerProgressIndicatorMode) {
7
- VideoTrimmerProgressIndicatorModeHiddenOnlyWhenTrimming,
8
- VideoTrimmerProgressIndicatorModeAlwaysShown,
9
- VideoTrimmerProgressIndicatorModeAlwaysHidden
10
- };
11
-
12
- typedef NS_ENUM(NSInteger, VideoTrimmerTrimmingState) {
13
- VideoTrimmerTrimmingStateNone,
14
- VideoTrimmerTrimmingStateLeading,
15
- VideoTrimmerTrimmingStateTrailing
16
- };
17
-
18
- @interface VideoTrimmer : UIControl
19
-
20
- // Main properties
21
- @property (nonatomic, strong) AVAsset *asset;
22
- @property (nonatomic, strong) AVVideoComposition *videoComposition;
23
- @property (nonatomic, assign) CMTime minimumDuration;
24
- @property (nonatomic, assign) CMTime maximumDuration;
25
- @property (nonatomic, assign) BOOL enableHapticFeedback;
26
-
27
- // Range properties
28
- @property (nonatomic, assign, readonly) CMTimeRange range;
29
- @property (nonatomic, assign) CMTimeRange selectedRange;
30
-
31
- // Progress properties
32
- @property (nonatomic, assign) VideoTrimmerProgressIndicatorMode progressIndicatorMode;
33
- @property (nonatomic, assign) CMTime progress;
34
-
35
- // State properties (read-only)
36
- @property (nonatomic, assign, readonly) VideoTrimmerTrimmingState trimmingState;
37
- @property (nonatomic, assign, readonly) BOOL isZoomedIn;
38
- @property (nonatomic, assign, readonly) CMTimeRange zoomedInRange;
39
- @property (nonatomic, assign, readonly) BOOL isScrubbing;
40
-
41
- // Computed properties
42
- @property (nonatomic, assign, readonly) CMTimeRange visibleRange;
43
- @property (nonatomic, assign, readonly) CMTime selectedTime;
44
-
45
- // Style properties
46
- @property (nonatomic, assign) CGFloat horizontalInset;
47
- @property (nonatomic, strong) UIColor *trackBackgroundColor;
48
- @property (nonatomic, strong) UIColor *thumbRestColor;
49
-
50
- // Gesture recognizers (read-only)
51
- @property (nonatomic, strong, readonly) UILongPressGestureRecognizer *leadingGestureRecognizer;
52
- @property (nonatomic, strong, readonly) UILongPressGestureRecognizer *trailingGestureRecognizer;
53
- @property (nonatomic, strong, readonly) UILongPressGestureRecognizer *progressGestureRecognizer;
54
- @property (nonatomic, strong, readonly) UILongPressGestureRecognizer *thumbnailInteractionGestureRecognizer;
55
-
56
- // Custom events
57
- + (UIControlEvents)didBeginTrimmingFromStart;
58
- + (UIControlEvents)leadingGrabberChanged;
59
- + (UIControlEvents)didEndTrimmingFromStart;
60
- + (UIControlEvents)didBeginTrimmingFromEnd;
61
- + (UIControlEvents)trailingGrabberChanged;
62
- + (UIControlEvents)didEndTrimmingFromEnd;
63
- + (UIControlEvents)didBeginScrubbing;
64
- + (UIControlEvents)progressChanged;
65
- + (UIControlEvents)didEndScrubbing;
66
-
67
- @end