-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
214 lines (195 loc) · 5.62 KB
/
App.js
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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Button,
View,
Platform,
NativeModules,
TouchableOpacity
} from 'react-native';
const {SdkEditorModule} = NativeModules;
// Set Banuba license token for Video and Photo Editor SDK
const LICENSE_TOKEN = SET LICENSE TOKEN
function initVideoEditorSDK() {
SdkEditorModule.initVideoEditorSDK(LICENSE_TOKEN);
}
function initPhotoEditorSDK() {
SdkEditorModule.initPhotoEditorSDK(LICENSE_TOKEN);
}
async function openVideoEditor() {
initVideoEditorSDK();
return await SdkEditorModule.openVideoEditor();
}
async function openVideoEditorPIP() {
initVideoEditorSDK();
return await SdkEditorModule.openVideoEditorPIP();
}
async function openVideoEditorTrimmer() {
initVideoEditorSDK();
return await SdkEditorModule.openVideoEditorTrimmer();
}
async function openPhotoEditor() {
if (Platform.OS === 'android') {
SdkEditorModule.releaseVideoEditor();
}
SdkEditorModule.initPhotoEditorSDK(LICENSE_TOKEN);
return await SdkEditorModule.openPhotoEditor();
}
export default class App extends Component {
constructor() {
super();
this.state = {
errorText: '',
};
}
handleVideoExport(response) {
console.log('Export completed successfully: video = ' + response?.videoUri + '; videoPreview = '
+ response?.previewUri);
}
handleSdkError(e) {
console.log('handle sdk error = ' + e.code);
var message = '';
switch (e.code) {
case 'ERR_SDK_NOT_INITIALIZED':
message = 'Banuba Video Editor SDK is not initialized: license token is unknown or incorrect.\nPlease check your license token or contact Banuba';
break;
case 'ERR_SDK_EDITOR_LICENSE_REVOKED':
message = 'License is revoked or expired. Please contact Banuba https://www.banuba.com/support';
break;
case 'ERR_MISSING_EXPORT_RESULT':
message = 'Missing video export result!';
case 'ERR_CODE_NO_HOST_CONTROLLER':
message = "Host Activity or ViewController does not exist!";
case 'ERR_VIDEO_EXPORT_CANCEL':
message = "Video export is canceled";
default:
message = '';
console.log(
'Banuba ' +
Platform.OS.toUpperCase() +
' Video Editor export video 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 and Photo Editor into React Native
</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, styles.photoButton]}
onPress={async () => {
openPhotoEditor()
.then(response => console.log('Exported photo = ' + response?.photoUri))
.catch(e => this.handleSdkError(e));
}}
>
<Text style={styles.buttonText}>Open Photo Editor</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={async () => {
openVideoEditor()
.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 () => {
openVideoEditorPIP()
.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 () => {
openVideoEditorTrimmer()
.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,
},
photoButton: {
backgroundColor: '#00ab41',
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '600',
},
});