-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.tsx
More file actions
340 lines (318 loc) · 10.1 KB
/
Copy pathApp.tsx
File metadata and controls
340 lines (318 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import { Component } from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
TouchableOpacity,
Platform,
} from 'react-native';
import VideoEditorPlugin, {
FeaturesConfigBuilder,
TemplatesConfig,
} from 'video-editor-react-native';
import {
launchImageLibrary,
type ImageLibraryOptions,
} from 'react-native-image-picker';
const LICENSE_TOKEN = SET BANUBA LICENSE TOKEN
const videoOptions: ImageLibraryOptions = { mediaType: 'video' };
type AppState = {
errorText: string;
};
export default class App extends Component<Record<string, never>, AppState> {
private featuresConfig = new FeaturesConfigBuilder()
// Specify your Config params in the builder below
//.setAudioBrowser(...)
//...
.build();
private templateBuilderFeaturesConfig = new FeaturesConfigBuilder()
.setTemplatesConfig(
new TemplatesConfig({
url: null,
enableBuilder: true,
termsOfUseUrl: 'https://www.banuba.com/terms',
})
)
.build();
// Export Data example
// private exportData = new ExportData({
// exportedVideos: [
// new ExportedVideo({
// fileName: 'export_hd',
// videoResolution: VideoResolution.fhd1080p,
// }),
// new ExportedVideo({
// fileName: 'export_auto',
// videoResolution: VideoResolution.auto,
// }),
// ],
// watermark: new Watermark({
// imagePath: 'watermark.png',
// alignment: WatermarkAlignment.topLeft,
// }),
// });
constructor(props: Record<string, never>) {
super(props);
this.state = {
errorText: '',
};
}
handleVideoExport(response: any) {
let exportedVideoSources = response?.exportedVideoSources;
let exportedPreview = response?.exportedPreview;
let exportedMeta = response?.exportedMeta;
let exportedDraftId = response?.savedDraftId;
console.log(
'Export completed successfully: video = ' +
exportedVideoSources +
'; videoPreview = ' +
exportedPreview +
'; meta = ' +
exportedMeta +
': savedDraftId = ' +
exportedDraftId
);
}
handleSdkError(e: { code?: string; message?: string }) {
console.log('handle sdk error = ' + e.code);
var message = '';
switch (e.code) {
case 'ERR_SDK_NOT_INITIALIZED':
message =
'Failed to initialize SDK!!! The license token is incorrect: empty or truncated. Please check the license token and try again.';
break;
case 'ERR_SDK_LICENSE_REVOKED':
message =
'WARNING!!! YOUR LICENSE TOKEN EITHER EXPIRED OR REVOKED! Please contact Banuba';
break;
case 'ERR_MISSING_EXPORT_RESULT':
message =
'Missing export result: video export has not been completed successfully. Please try again';
break;
case 'ERR_MISSING_HOST':
message = 'Missing host Activity to start video editor';
break;
case 'ERR_MISSING_DRAFT_ID':
message = "Provided Draft ID doesn't exist!";
break;
case 'ERR_VIDEO_EXPORT_CANCEL':
message = 'The user has canceled video editing flow!';
break;
case 'ERR_ENTRY_NOT_SUPPORTED':
message = 'Draft by ID is not supported on Android';
break;
case 'ERR_INVALID_PARAMS':
message = e.message ?? '';
break;
default:
message = '';
console.log(
'Banuba ' +
Platform.OS.toUpperCase() +
' Video Editor export failed = ' +
e
);
break;
}
this.setState({ errorText: message });
}
render() {
return (
<View style={styles.container}>
<SafeAreaView style={styles.appBar}>
<Text style={styles.appBarTitle}>
Video Editor React Native plugin
</Text>
</SafeAreaView>
<View style={styles.content}>
<View style={styles.errorContainer}>
{this.state.errorText ? (
<Text style={styles.errorText}>{this.state.errorText}</Text>
) : null}
</View>
<View style={styles.buttonsContainer}>
<TouchableOpacity
style={styles.button}
onPress={async () => {
const videoEditor = new VideoEditorPlugin();
videoEditor
.openFromCamera(LICENSE_TOKEN, this.featuresConfig)
.then((response) => this.handleVideoExport(response))
.catch((e) => this.handleSdkError(e));
}}
>
<Text style={styles.buttonText}>Open Video Editor - Default</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={async () => {
const videoEditor = new VideoEditorPlugin();
videoEditor
.openFromTemplates(LICENSE_TOKEN, this.featuresConfig)
.then((response) => this.handleVideoExport(response))
.catch((e) => this.handleSdkError(e));
}}
>
<Text style={styles.buttonText}>
Open Video Editor - Templates
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={async () => {
const videoEditor = new VideoEditorPlugin();
videoEditor
.openFromTemplates(
LICENSE_TOKEN,
this.templateBuilderFeaturesConfig
)
.then((response) => this.handleVideoExport(response))
.catch((e) => this.handleSdkError(e));
}}
>
<Text style={styles.buttonText}>
Open Video Editor - Templates Builder
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={async () => {
launchImageLibrary(videoOptions, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.warn('User cancelled photo picker');
} else if (response.errorCode) {
console.warn('ImagePicker Error: ', response.errorMessage);
} else {
let videoUri = response.assets?.[0]?.uri;
if (!videoUri) {
console.warn(
'Cannot start video editor in pip mode: please pick video file'
);
return;
}
console.log('# Picked video source for pip = ' + videoUri);
const videoEditor = new VideoEditorPlugin();
videoEditor
.openFromPip(LICENSE_TOKEN, this.featuresConfig, videoUri)
.then((exportResponse) => {
this.handleVideoExport(exportResponse);
})
.catch((e) => {
this.handleSdkError(e);
});
}
});
}}
>
<Text style={styles.buttonText}>Open Video Editor - PIP</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={async () => {
launchImageLibrary(videoOptions, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.warn('User cancelled photo picker');
} else if (response.errorCode) {
console.warn('ImagePicker Error: ', response.errorMessage);
} else {
let videoUri = response.assets?.[0]?.uri;
if (!videoUri) {
console.warn(
'Cannot start video editor in trimmer mode: please pick video file'
);
return;
}
console.log(
'# Picked video source for trimmer = ' + videoUri
);
let videoSources = [videoUri];
const videoEditor = new VideoEditorPlugin();
videoEditor
.openFromTrimmer(
LICENSE_TOKEN,
this.featuresConfig,
videoSources
)
.then((exportResponse) => {
this.handleVideoExport(exportResponse);
})
.catch((e) => {
this.handleSdkError(e);
});
}
});
}}
>
<Text style={styles.buttonText}>Open Video Editor - Trimmer</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
},
appBar: {
backgroundColor: 'black',
minHeight: 56,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
},
appBarTitle: {
color: 'white',
fontSize: 18,
fontWeight: '600',
textAlign: 'center',
},
content: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
},
errorContainer: {
position: 'absolute',
top: 8,
left: 16,
right: 16,
alignItems: 'center',
},
buttonsContainer: {
alignItems: 'center',
width: '100%',
maxWidth: 300,
},
errorText: {
color: '#ff0000',
fontSize: 17,
textAlign: 'center',
},
button: {
backgroundColor: 'black',
height: 50,
borderRadius: 30,
alignItems: 'center',
justifyContent: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 6 },
shadowOpacity: 0.35,
shadowRadius: 8,
elevation: 10,
width: '100%',
marginVertical: 10,
},
buttonText: {
color: 'white',
fontSize: 13,
fontWeight: '600',
textAlign: 'center',
},
});