/
App.js
177 lines (158 loc) · 4.99 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
import React, {Component} from 'react';
import {
StyleSheet,
Text,
Button,
View,
Platform,
NativeModules,
} from 'react-native';
const {SdkEditorModule} = NativeModules;
// Set Banuba license token for Video and Photo Editor SDK
const LICENSE_TOKEN = SET LICENSE TOKEN
function initSDK() {
SdkEditorModule.initSDK(LICENSE_TOKEN);
}
async function openVideoEditor() {
initSDK();
return await SdkEditorModule.openVideoEditor();
}
async function openVideoEditorPIP() {
initSDK();
return await SdkEditorModule.openVideoEditorPIP();
}
async function openVideoEditorTrimmer() {
initSDK();
return await SdkEditorModule.openVideoEditorTrimmer();
}
async function openIosPhotoEditor() {
await SdkEditorModule.initPhotoEditor(LICENSE_TOKEN);
return await SdkEditorModule.openPhotoEditor();
}
async function openAndroidPhotoEditor() {
initSDK();
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);
}
render() {
return (
<View style={styles.container}>
<Text style={{padding: 16, textAlign: 'center', fontSize: 18 }}>
Sample integration of Banuba Video and Photo Editor into React Native
</Text>
<Text
style={{
padding: 16,
textAlign: 'center',
color: '#ff0000',
fontSize: 16,
fontWeight: '800',
}}>
{this.state.errorText}
</Text>
<View style={{marginVertical: 8}}>
<Button
title="Open Photo Editor"
color="#00ab41"
onPress={async () => {
if (Platform.OS === 'android') {
openAndroidPhotoEditor()
.then(response => {
console.log('Exported photo = ' + response?.photoUri);
})
.catch(e => {
this.handleSdkError(e);
});
} else {
openIosPhotoEditor()
.then(response => {
console.log('Exported photo = ' + response?.photoUri);
})
.catch(e => {
this.handleSdkError(e);
});
}
}}
/>
</View>
<View style={{marginVertical: 8}}>
<Button
title="Open Video Editor - Default"
onPress={async () => {
openVideoEditor()
.then(response => { this.handleVideoExport(response); })
.catch(e => { this.handleSdkError(e); });
}}
/>
</View>
<View style={{marginVertical: 8}}>
<Button
title="Open Video Editor - PIP"
onPress={async () => {
openVideoEditorPIP()
.then(response => { this.handleVideoExport(response); })
.catch(e => { this.handleSdkError(e); });
}}
/>
</View>
<View style={{marginVertical: 8}}>
<Button
title="Open Video Editor - Trimmer"
onPress={async () => {
openVideoEditorTrimmer()
.then(response => { this.handleVideoExport(response); })
.catch(e => { this.handleSdkError(e); });
}}
/>
</View>
</View>
);
}
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/faq/kb-tickets/new';
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});
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
marginVertical: 16,
alignItems: 'center',
justifyContent: 'center',
},
});