-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
244 lines (225 loc) · 7.34 KB
/
App.tsx
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
import React, { Component } from 'react';
import { StyleSheet, View, Text, Button, TouchableOpacity, Platform } from 'react-native';
import VideoEditorPlugin, {
AiClipping,
AiCaptions,
AudioBrowser,
AudioBrowserSource,
DraftsConfig,
DraftsOption,
EditorConfig,
GifPickerConfig,
FeaturesConfigBuilder,
ExportData,
ExportedVideo,
Watermark,
VideoResolution,
WatermarkAlignment,
VideoDurationConfig,
} from 'video-editor-react-native';
import { launchImageLibrary } from 'react-native-image-picker';
const LICENSE_TOKEN = SET BANUBA LICENSE TOKEN
const videoOptions = { mediaType: 'video' };
export default class App extends Component {
private featuresConfig = new FeaturesConfigBuilder()
// Specify your Config params in the builder below
//.setAudioBrowser(...)
//...
.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() {
super();
this.state = {
errorText: '',
};
}
handleVideoExport(response) {
let exportedVideoSources = response?.exportedVideoSources
let exportedPreview = response?.exportedPreview
let exportedMeta = response?.exportedMeta
console.log('Export completed successfully: video = ' + exportedVideoSources + '; videoPreview = '
+ exportedPreview + "; meta = " + exportedMeta);
}
handleSdkError(e) {
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';
case 'ERR_MISSING_HOST':
message = "Missing host Activity to start video editor";
case 'ERR_VIDEO_EXPORT_CANCEL':
message = "The user has canceled video editing flow!";
case 'ERR_INVALID_PARAMS':
message = e.message;
default:
message = '';
console.log(
'Banuba ' +
Platform.OS.toUpperCase() +
' Video Editor export failed = ' +
e,
);
break;
}
this.setState({ errorText: message });
}
render() {
return (
<View style={styles.container}>
<View style={styles.headerContainer}>
<Text style={styles.title}>
Sample integration of Banuba Video into React Native project
</Text>
</View>
<View style={styles.buttonsWrapper}>
<View style={styles.buttonsContainer}>
{this.state.errorText ? (
<Text style={styles.errorText}>{this.state.errorText}</Text>
) : null}
<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 () => {
launchImageLibrary(
videoOptions,
(response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.warn('User cancelled photo picker');
} else if (response.error) {
console.warn('ImagePicker Error: ', response.error);
} else {
let videoUri = response.uri || response.assets?.[0]?.uri;
console.log('# Picked video source for pip = ' + videoUri);
const videoEditor = new VideoEditorPlugin();
videoEditor.openFromPip(LICENSE_TOKEN, this.featuresConfig, videoUri)
.then(response => { this.handleVideoExport(response); })
.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.error) {
console.warn('ImagePicker Error: ', response.error);
} else {
let videoUri = response.uri || response.assets?.[0]?.uri;
console.log('# Picked video source for trimmer = ' + videoUri);
let videoSources = [videoUri];
const videoEditor = new VideoEditorPlugin();
videoEditor.openFromTrimmer(LICENSE_TOKEN, this.featuresConfig, videoSources)
.then(response => { this.handleVideoExport(response); })
.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,
},
headerContainer: {
height: '33%',
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
},
title: {
fontSize: 18,
textAlign: 'center',
},
buttonsWrapper: {
position: 'absolute',
top: 50,
bottom: 0,
left: 0,
right: 0,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
},
buttonsContainer: {
alignItems: 'center',
width: '100%',
maxWidth: 300,
},
errorText: {
color: '#ff0000',
fontSize: 16,
fontWeight: '800',
textAlign: 'center',
marginBottom: 16,
},
button: {
backgroundColor: '#007bff',
paddingVertical: 12,
borderRadius: 30,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 4 },
shadowOpacity: 0.3,
shadowRadius: 5,
elevation: 5,
width: '100%',
marginVertical: 8,
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '600',
},
});