-
Notifications
You must be signed in to change notification settings - Fork 10
/
App.js
201 lines (183 loc) · 6.15 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
import { StatusBar } from "expo-status-bar";
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Button,
View,
Platform,
NativeModules,
} from "react-native";
const { VideoEditorModule } = NativeModules;
// Set Banuba license token for Video Editor SDK
const LICENSE_TOKEN = SET LICENSE TOKEN
const ERR_SDK_NOT_INITIALIZED_CODE = 'ERR_VIDEO_EDITOR_NOT_INITIALIZED';
const 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';
const ERR_LICENSE_REVOKED_CODE = 'ERR_VIDEO_EDITOR_LICENSE_REVOKED';
const ERR_LICENSE_REVOKED_MESSAGE = 'License is revoked or expired. Please contact Banuba https://www.banuba.com/faq/kb-tickets/new';
function initVideoEditor() {
VideoEditorModule.initVideoEditor(LICENSE_TOKEN);
}
async function startIosVideoEditor() {
initVideoEditor();
return await VideoEditorModule.openVideoEditor();
}
async function startIosVideoEditorPIP() {
initVideoEditor();
return await VideoEditorModule.openVideoEditorPIP();
}
async function startIosVideoEditorTrimmer() {
initVideoEditor();
return await VideoEditorModule.openVideoEditorTrimmer();
}
async function startAndroidVideoEditor() {
initVideoEditor();
return await VideoEditorModule.openVideoEditor();
}
async function startAndroidVideoEditorPIP() {
initVideoEditor();
return await VideoEditorModule.openVideoEditorPIP();
}
async function startAndroidVideoEditorTrimmer() {
initVideoEditor();
return await VideoEditorModule.openVideoEditorTrimmer();
}
export default class App extends Component {
constructor() {
super()
this.state = {
errorText: ''
}
}
handleExportException(e) {
var message = '';
switch (e.code) {
case ERR_SDK_NOT_INITIALIZED_CODE:
message = ERR_SDK_NOT_INITIALIZED_MESSAGE;
break;
case ERR_LICENSE_REVOKED_CODE:
message = ERR_LICENSE_REVOKED_MESSAGE;
break;
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}>
<Text style={{ padding: 16, textAlign: 'center' }}>
Sample integration of Banuba Video Editor into React Native Expo project
</Text>
<Text style={{ padding: 16, textAlign: 'center', color: '#ff0000', fontSize: 16, fontWeight: "800" }}>
{this.state.errorText}
</Text>
<View style={{ marginVertical: 8 }}>
<Button
title="Open Video Editor - Default"
onPress={async () => {
if (Platform.OS === 'android') {
startAndroidVideoEditor()
.then((videoUri) => {
console.log(
"Banuba Android Video Editor export video completed successfully. Video uri = " +
videoUri
);
})
.catch((e) => {
this.handleExportException(e);
});
} else {
startIosVideoEditor()
.then((response) => {
const exportedVideoUri = response?.videoUri;
console.log(
"Banuba iOS Video Editor export video completed successfully. Video uri = " +
exportedVideoUri
);
})
.catch((e) => {
this.handleExportException(e);
});
}
}} />
</View>
<View style={{ marginVertical: 8 }}>
<Button
title="Open Video Editor - PIP"
color="#00ab41"
onPress={async () => {
if (Platform.OS === 'android') {
startAndroidVideoEditorPIP()
.then(videoUri => {
console.log(
'Banuba Android Video Editor export video completed successfully. Video uri = ' +
videoUri
);
})
.catch(e => {
this.handleExportException(e);
});
} else {
startIosVideoEditorPIP()
.then(response => {
const exportedVideoUri = response?.videoUri;
console.log(
'Banuba iOS Video Editor export video completed successfully. Video uri = ' +
exportedVideoUri
);
})
.catch(e => {
this.handleExportException(e);
});
}
}} />
</View>
<View style={{ marginVertical: 8 }}>
<Button
title="Open Video Editor - Trimmer"
color="#ff0000"
onPress={async () => {
if (Platform.OS === 'android') {
startAndroidVideoEditorTrimmer()
.then(videoUri => {
console.log(
'Banuba Android Video Editor export video completed successfully. Video uri = ' +
videoUri
);
})
.catch(e => {
this.handleExportException(e);
});
} else {
startIosVideoEditorTrimmer()
.then(response => {
const exportedVideoUri = response?.videoUri;
console.log(
'Banuba iOS Video Editor export video completed successfully. Video uri = ' +
exportedVideoUri
);
})
.catch(e => {
this.handleExportException(e);
});
}
}} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
marginVertical: 24,
alignItems: "center",
justifyContent: "center",
},
});