react-native-video-trim 1.0.9 → 1.0.11
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 +38 -5
- package/android/src/main/java/com/videotrim/VideoTrimModule.java +96 -12
- package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +1 -0
- package/android/src/main/java/com/videotrim/utils/StorageUtil.java +14 -143
- package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +2 -10
- package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +5 -32
- package/android/src/main/res/values/strings.xml +1 -1
- package/ios/VideoTrim.mm +6 -1
- package/ios/VideoTrim.swift +279 -115
- package/ios/VideoTrimmer.swift +808 -0
- package/ios/VideoTrimmerThumb.swift +119 -0
- package/ios/VideoTrimmerViewController.swift +292 -0
- package/lib/commonjs/index.js +64 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +61 -4
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +46 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-video-trim.podspec +1 -0
- package/src/index.tsx +75 -5
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
export interface EditorConfig {
|
|
2
2
|
saveToPhoto?: boolean;
|
|
3
|
+
removeAfterSavedToPhoto?: boolean;
|
|
3
4
|
maxDuration?: number;
|
|
4
|
-
title?: string;
|
|
5
5
|
cancelButtonText?: string;
|
|
6
6
|
saveButtonText?: string;
|
|
7
|
+
enableCancelDialog?: boolean;
|
|
8
|
+
cancelDialogTitle?: string;
|
|
9
|
+
cancelDialogMessage?: string;
|
|
10
|
+
cancelDialogCancelText?: string;
|
|
11
|
+
cancelDialogConfirmText?: string;
|
|
12
|
+
enableSaveDialog?: boolean;
|
|
13
|
+
saveDialogTitle?: string;
|
|
14
|
+
saveDialogMessage?: string;
|
|
15
|
+
saveDialogCancelText?: string;
|
|
16
|
+
saveDialogConfirmText?: string;
|
|
17
|
+
trimmingText?: string;
|
|
7
18
|
}
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Delete a file
|
|
21
|
+
*
|
|
22
|
+
* @param {string} videoPath: absolute non-empty file path to edit
|
|
23
|
+
* @param {EditorConfig} config: editor configuration
|
|
24
|
+
* @returns {void} A **Promise** which resolves `void`
|
|
25
|
+
*/
|
|
26
|
+
export declare function showEditor(filePath: string, config?: EditorConfig): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete a file
|
|
29
|
+
*
|
|
30
|
+
* @param {string} filePath: absolute non-empty file path to check if editable
|
|
31
|
+
* @returns {Promise} A **Promise** which resolves `true` if editable
|
|
32
|
+
*/
|
|
33
|
+
export declare function isValidVideo(filePath: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Clean output files generated at all time
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<string[]>} A **Promise** which resolves to array of files
|
|
38
|
+
*/
|
|
39
|
+
export declare function listFiles(): Promise<string[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Clean output files generated at all time
|
|
42
|
+
*
|
|
43
|
+
* @returns {Promise} A **Promise** which resolves to number of deleted files
|
|
44
|
+
*/
|
|
45
|
+
export declare function cleanFiles(): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a file
|
|
48
|
+
*
|
|
49
|
+
* @param {string} filePath: absolute non-empty file path to delete
|
|
50
|
+
* @returns {Promise} A **Promise** which resolves `true` if successful
|
|
51
|
+
*/
|
|
52
|
+
export declare function deleteFile(filePath: string): Promise<boolean>;
|
|
10
53
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,
|
|
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ec.new do |s|
|
|
|
15
15
|
s.source = { :git => "https://github.com/maitrungduc1410/react-native-video-trim.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
|
+
s.dependency 'ffmpeg-kit-ios-min', '~> 6.0'
|
|
18
19
|
|
|
19
20
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
20
21
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
package/src/index.tsx
CHANGED
|
@@ -19,18 +19,40 @@ const VideoTrim = NativeModules.VideoTrim
|
|
|
19
19
|
|
|
20
20
|
export interface EditorConfig {
|
|
21
21
|
saveToPhoto?: boolean;
|
|
22
|
+
removeAfterSavedToPhoto?: boolean;
|
|
22
23
|
maxDuration?: number;
|
|
23
|
-
title?: string;
|
|
24
24
|
cancelButtonText?: string;
|
|
25
25
|
saveButtonText?: string;
|
|
26
|
+
enableCancelDialog?: boolean;
|
|
27
|
+
cancelDialogTitle?: string;
|
|
28
|
+
cancelDialogMessage?: string;
|
|
29
|
+
cancelDialogCancelText?: string;
|
|
30
|
+
cancelDialogConfirmText?: string;
|
|
31
|
+
enableSaveDialog?: boolean;
|
|
32
|
+
saveDialogTitle?: string;
|
|
33
|
+
saveDialogMessage?: string;
|
|
34
|
+
saveDialogCancelText?: string;
|
|
35
|
+
saveDialogConfirmText?: string;
|
|
36
|
+
trimmingText?: string;
|
|
26
37
|
}
|
|
27
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Delete a file
|
|
41
|
+
*
|
|
42
|
+
* @param {string} videoPath: absolute non-empty file path to edit
|
|
43
|
+
* @param {EditorConfig} config: editor configuration
|
|
44
|
+
* @returns {void} A **Promise** which resolves `void`
|
|
45
|
+
*/
|
|
28
46
|
export async function showEditor(
|
|
29
|
-
|
|
47
|
+
filePath: string,
|
|
30
48
|
config: EditorConfig = {}
|
|
31
49
|
): Promise<void> {
|
|
50
|
+
if (!filePath?.trim().length) {
|
|
51
|
+
throw new Error('File path cannot be empty!');
|
|
52
|
+
}
|
|
53
|
+
|
|
32
54
|
const { saveToPhoto = true } = config;
|
|
33
|
-
const outputPath = await VideoTrim.showEditor(
|
|
55
|
+
const outputPath = await VideoTrim.showEditor(filePath, config);
|
|
34
56
|
|
|
35
57
|
if (Platform.OS === 'android') {
|
|
36
58
|
if (saveToPhoto) {
|
|
@@ -38,6 +60,10 @@ export async function showEditor(
|
|
|
38
60
|
if (Platform.Version >= 33) {
|
|
39
61
|
// since android 13 it's not needed to request permission for write storage: https://github.com/facebook/react-native/issues/36714#issuecomment-1491338276
|
|
40
62
|
await VideoTrim.saveVideo(outputPath);
|
|
63
|
+
|
|
64
|
+
if (config.removeAfterSavedToPhoto) {
|
|
65
|
+
deleteFile(outputPath);
|
|
66
|
+
}
|
|
41
67
|
} else {
|
|
42
68
|
const granted = await PermissionsAndroid.request(
|
|
43
69
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE!,
|
|
@@ -51,6 +77,10 @@ export async function showEditor(
|
|
|
51
77
|
);
|
|
52
78
|
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
|
53
79
|
await VideoTrim.saveVideo(outputPath);
|
|
80
|
+
|
|
81
|
+
if (config.removeAfterSavedToPhoto) {
|
|
82
|
+
deleteFile(outputPath);
|
|
83
|
+
}
|
|
54
84
|
} else {
|
|
55
85
|
throw new Error('Photos Library permission denied');
|
|
56
86
|
}
|
|
@@ -66,6 +96,46 @@ export async function showEditor(
|
|
|
66
96
|
}
|
|
67
97
|
}
|
|
68
98
|
|
|
69
|
-
|
|
70
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Delete a file
|
|
101
|
+
*
|
|
102
|
+
* @param {string} filePath: absolute non-empty file path to check if editable
|
|
103
|
+
* @returns {Promise} A **Promise** which resolves `true` if editable
|
|
104
|
+
*/
|
|
105
|
+
export function isValidVideo(filePath: string): Promise<boolean> {
|
|
106
|
+
if (!filePath?.trim().length) {
|
|
107
|
+
throw new Error('File path cannot be empty!');
|
|
108
|
+
}
|
|
109
|
+
return VideoTrim.isValidVideo(filePath);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Clean output files generated at all time
|
|
114
|
+
*
|
|
115
|
+
* @returns {Promise<string[]>} A **Promise** which resolves to array of files
|
|
116
|
+
*/
|
|
117
|
+
export function listFiles(): Promise<string[]> {
|
|
118
|
+
return VideoTrim.listFiles();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Clean output files generated at all time
|
|
123
|
+
*
|
|
124
|
+
* @returns {Promise} A **Promise** which resolves to number of deleted files
|
|
125
|
+
*/
|
|
126
|
+
export function cleanFiles(): Promise<number> {
|
|
127
|
+
return VideoTrim.cleanFiles();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Delete a file
|
|
132
|
+
*
|
|
133
|
+
* @param {string} filePath: absolute non-empty file path to delete
|
|
134
|
+
* @returns {Promise} A **Promise** which resolves `true` if successful
|
|
135
|
+
*/
|
|
136
|
+
export function deleteFile(filePath: string): Promise<boolean> {
|
|
137
|
+
if (!filePath?.trim().length) {
|
|
138
|
+
throw new Error('File path cannot be empty!');
|
|
139
|
+
}
|
|
140
|
+
return VideoTrim.deleteFile(filePath);
|
|
71
141
|
}
|