react-native-video-trim 4.0.0 → 4.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.
- package/README.md +36 -8
- package/VideoTrim.podspec +1 -1
- package/android/build.gradle +9 -1
- package/android/gradle.properties +2 -0
- package/android/src/main/java/com/margelo/nitro/videotrim/VideoTrim.kt +138 -121
- package/android/src/main/java/com/margelo/nitro/videotrim/utils/VideoTrimmerUtil.java +29 -21
- package/android/src/main/java/com/margelo/nitro/videotrim/widgets/VideoTrimmerView.java +10 -6
- package/ios/VideoTrim.swift +7 -0
- package/ios/VideoTrimImpl.swift +221 -124
- package/lib/module/index.js +38 -11
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/VideoTrim.nitro.d.ts +74 -57
- package/lib/typescript/src/VideoTrim.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +9 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JEditorConfig.hpp +54 -46
- package/nitrogen/generated/android/c++/JHybridVideoTrimSpec.cpp +20 -0
- package/nitrogen/generated/android/c++/JHybridVideoTrimSpec.hpp +1 -0
- package/nitrogen/generated/android/c++/JTrimOptions.hpp +109 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/videotrim/EditorConfig.kt +14 -12
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/videotrim/HybridVideoTrimSpec.kt +4 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/videotrim/TrimOptions.kt +40 -0
- package/nitrogen/generated/ios/VideoTrim-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/VideoTrim-Swift-Cxx-Bridge.hpp +43 -0
- package/nitrogen/generated/ios/VideoTrim-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridVideoTrimSpecSwift.hpp +11 -0
- package/nitrogen/generated/ios/swift/EditorConfig.swift +116 -94
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridVideoTrimSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridVideoTrimSpec_cxx.swift +19 -0
- package/nitrogen/generated/ios/swift/TrimOptions.swift +189 -0
- package/nitrogen/generated/shared/c++/EditorConfig.hpp +54 -46
- package/nitrogen/generated/shared/c++/HybridVideoTrimSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridVideoTrimSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/TrimOptions.hpp +125 -0
- package/package.json +1 -1
- package/src/VideoTrim.nitro.ts +76 -57
- package/src/index.tsx +45 -11
package/src/VideoTrim.nitro.ts
CHANGED
|
@@ -1,16 +1,80 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
4
|
-
/**
|
|
5
|
-
* Enable haptic feedback
|
|
6
|
-
* @default true
|
|
7
|
-
*/
|
|
8
|
-
enableHapticFeedback: boolean;
|
|
3
|
+
export interface BaseOptions {
|
|
9
4
|
/**
|
|
10
5
|
* Save the output file to Photos Library. Only video is supported. Note that you have to make sure you have permission to save to Photos Library.
|
|
11
6
|
* @default false
|
|
12
7
|
*/
|
|
13
8
|
saveToPhoto: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Type of the file to edit. If video file, recommend to use `video`. If audio file, recommend to use `audio`.
|
|
11
|
+
* @default "video"
|
|
12
|
+
*/
|
|
13
|
+
type: string;
|
|
14
|
+
/**
|
|
15
|
+
* Output file extension. If video file, recommend to use `mp4` or `mov`. If audio file, recommend to use `wav` or `m4a`.
|
|
16
|
+
* @default "mp4"
|
|
17
|
+
* @example "mp4", "mov", "wav", "m4a", "3gp", "avi", "mkv", "flv", "wmv", "webm"
|
|
18
|
+
*/
|
|
19
|
+
outputExt: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to open Documents app after finish editing
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
openDocumentsOnFinish: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to open Share Sheet after finish editing
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
openShareSheetOnFinish: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Remove the file after saved to Photos Library
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
removeAfterSavedToPhoto: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Remove the file after failed to save to Photos Library
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
removeAfterFailedToSavePhoto: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Remove the file after saved to Documents app
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
removeAfterSavedToDocuments: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Remove the file after failed to save to Documents app
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
removeAfterFailedToSaveDocuments: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Remove the file after shared to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
removeAfterShared: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Remove the file after failed to share to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
removeAfterFailedToShare: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Enable rotation
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
enableRotation: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Rotation angle in degrees
|
|
67
|
+
* @default 0
|
|
68
|
+
*/
|
|
69
|
+
rotationAngle: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface EditorConfig extends BaseOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Enable haptic feedback
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
enableHapticFeedback: boolean;
|
|
14
78
|
maxDuration: number;
|
|
15
79
|
/**
|
|
16
80
|
* Minimum duration for trimmer
|
|
@@ -87,57 +151,6 @@ export interface EditorConfig {
|
|
|
87
151
|
* @default false
|
|
88
152
|
*/
|
|
89
153
|
fullScreenModalIOS: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Type of the file to edit. If video file, recommend to use `video`. If audio file, recommend to use `audio`.
|
|
92
|
-
* @default "video"
|
|
93
|
-
*/
|
|
94
|
-
type: string;
|
|
95
|
-
/**
|
|
96
|
-
* Output file extension. If video file, recommend to use `mp4` or `mov`. If audio file, recommend to use `wav` or `m4a`.
|
|
97
|
-
* @default "mp4"
|
|
98
|
-
* @example "mp4", "mov", "wav", "m4a", "3gp", "avi", "mkv", "flv", "wmv", "webm"
|
|
99
|
-
*/
|
|
100
|
-
outputExt: string;
|
|
101
|
-
/**
|
|
102
|
-
* Whether to open Documents app after finish editing
|
|
103
|
-
* @default false
|
|
104
|
-
*/
|
|
105
|
-
openDocumentsOnFinish: boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Whether to open Share Sheet after finish editing
|
|
108
|
-
* @default false
|
|
109
|
-
*/
|
|
110
|
-
openShareSheetOnFinish: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Remove the file after saved to Photos Library
|
|
113
|
-
* @default false
|
|
114
|
-
*/
|
|
115
|
-
removeAfterSavedToPhoto: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Remove the file after failed to save to Photos Library
|
|
118
|
-
* @default false
|
|
119
|
-
*/
|
|
120
|
-
removeAfterFailedToSavePhoto: boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Remove the file after saved to Documents app
|
|
123
|
-
* @default false
|
|
124
|
-
*/
|
|
125
|
-
removeAfterSavedToDocuments: boolean;
|
|
126
|
-
/**
|
|
127
|
-
* Remove the file after failed to save to Documents app
|
|
128
|
-
* @default false
|
|
129
|
-
*/
|
|
130
|
-
removeAfterFailedToSaveDocuments: boolean;
|
|
131
|
-
/**
|
|
132
|
-
* Remove the file after shared to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
|
|
133
|
-
* @default false
|
|
134
|
-
*/
|
|
135
|
-
removeAfterShared: boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Remove the file after failed to share to other apps. Currently only support iOS, on Android there's no way to detect if the file is shared or not.
|
|
138
|
-
* @default false
|
|
139
|
-
*/
|
|
140
|
-
removeAfterFailedToShare: boolean;
|
|
141
154
|
/**
|
|
142
155
|
* Whether to enable autoplay on load
|
|
143
156
|
*/
|
|
@@ -223,6 +236,11 @@ export interface EditorConfig {
|
|
|
223
236
|
alertOnFailCloseText: string;
|
|
224
237
|
}
|
|
225
238
|
|
|
239
|
+
export interface TrimOptions extends BaseOptions {
|
|
240
|
+
startTime: number; // in milliseconds
|
|
241
|
+
endTime: number; // in milliseconds
|
|
242
|
+
}
|
|
243
|
+
|
|
226
244
|
export interface FileValidationResult {
|
|
227
245
|
isValid: boolean;
|
|
228
246
|
fileType: string;
|
|
@@ -241,4 +259,5 @@ export interface VideoTrim
|
|
|
241
259
|
deleteFile(filePath: string): Promise<boolean>;
|
|
242
260
|
closeEditor(onComplete: () => void): void;
|
|
243
261
|
isValidFile(url: string): Promise<FileValidationResult>;
|
|
262
|
+
trim(url: string, options: TrimOptions): Promise<string>;
|
|
244
263
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
2
|
import type {
|
|
3
|
+
BaseOptions,
|
|
3
4
|
EditorConfig,
|
|
4
5
|
FileValidationResult,
|
|
6
|
+
TrimOptions,
|
|
5
7
|
VideoTrim,
|
|
6
8
|
} from './VideoTrim.nitro';
|
|
7
9
|
import { processColor } from 'react-native';
|
|
@@ -9,12 +11,30 @@ import { processColor } from 'react-native';
|
|
|
9
11
|
const VideoTrimHybridObject =
|
|
10
12
|
NitroModules.createHybridObject<VideoTrim>('VideoTrim');
|
|
11
13
|
|
|
14
|
+
function createBaseOptions(overrides: Partial<BaseOptions> = {}): BaseOptions {
|
|
15
|
+
return {
|
|
16
|
+
saveToPhoto: false,
|
|
17
|
+
type: 'video',
|
|
18
|
+
outputExt: 'mp4',
|
|
19
|
+
openDocumentsOnFinish: false,
|
|
20
|
+
openShareSheetOnFinish: false,
|
|
21
|
+
removeAfterSavedToPhoto: false,
|
|
22
|
+
removeAfterFailedToSavePhoto: false,
|
|
23
|
+
removeAfterSavedToDocuments: false,
|
|
24
|
+
removeAfterFailedToSaveDocuments: false,
|
|
25
|
+
removeAfterShared: false,
|
|
26
|
+
removeAfterFailedToShare: false,
|
|
27
|
+
enableRotation: false,
|
|
28
|
+
rotationAngle: 0,
|
|
29
|
+
...overrides,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
function createEditorConfig(
|
|
13
34
|
overrides: Partial<EditorConfig> = {}
|
|
14
35
|
): EditorConfig {
|
|
15
36
|
return {
|
|
16
37
|
enableHapticFeedback: true,
|
|
17
|
-
saveToPhoto: false,
|
|
18
38
|
maxDuration: -1, // Adjust default as needed
|
|
19
39
|
minDuration: 1000,
|
|
20
40
|
cancelButtonText: 'Cancel',
|
|
@@ -31,16 +51,6 @@ function createEditorConfig(
|
|
|
31
51
|
saveDialogConfirmText: 'Proceed',
|
|
32
52
|
trimmingText: 'Trimming video...',
|
|
33
53
|
fullScreenModalIOS: false,
|
|
34
|
-
type: 'video',
|
|
35
|
-
outputExt: 'mp4',
|
|
36
|
-
openDocumentsOnFinish: false,
|
|
37
|
-
openShareSheetOnFinish: false,
|
|
38
|
-
removeAfterSavedToPhoto: false,
|
|
39
|
-
removeAfterFailedToSavePhoto: false,
|
|
40
|
-
removeAfterSavedToDocuments: false,
|
|
41
|
-
removeAfterFailedToSaveDocuments: false,
|
|
42
|
-
removeAfterShared: false,
|
|
43
|
-
removeAfterFailedToShare: false,
|
|
44
54
|
autoplay: false, // Adjust default as needed
|
|
45
55
|
jumpToPositionOnLoad: -1,
|
|
46
56
|
closeWhenFinish: true,
|
|
@@ -59,6 +69,16 @@ function createEditorConfig(
|
|
|
59
69
|
alertOnFailMessage:
|
|
60
70
|
'Fail to load media. Possibly invalid file or no network connection',
|
|
61
71
|
alertOnFailCloseText: 'Close',
|
|
72
|
+
...createBaseOptions(overrides),
|
|
73
|
+
...overrides,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function createTrimOptions(overrides: Partial<TrimOptions> = {}): TrimOptions {
|
|
78
|
+
return {
|
|
79
|
+
startTime: 0,
|
|
80
|
+
endTime: 1000,
|
|
81
|
+
...createBaseOptions(overrides),
|
|
62
82
|
...overrides,
|
|
63
83
|
};
|
|
64
84
|
}
|
|
@@ -138,3 +158,17 @@ export function closeEditor(onComplete?: () => void): void {
|
|
|
138
158
|
export function isValidFile(url: string): Promise<FileValidationResult> {
|
|
139
159
|
return VideoTrimHybridObject.isValidFile(url);
|
|
140
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Trim a video file
|
|
164
|
+
*
|
|
165
|
+
* @param {string} url: absolute non-empty file path to edit
|
|
166
|
+
* @param {TrimOptions} options: trim options
|
|
167
|
+
* @returns {Promise<string>} A **Promise** which resolves to the trimmed file path
|
|
168
|
+
*/
|
|
169
|
+
export function trim(
|
|
170
|
+
url: string,
|
|
171
|
+
options: Partial<TrimOptions>
|
|
172
|
+
): Promise<string> {
|
|
173
|
+
return VideoTrimHybridObject.trim(url, createTrimOptions(options));
|
|
174
|
+
}
|