-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
75 lines (68 loc) · 2.17 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
/* eslint-disable react-native/no-inline-styles */
import BanubaSdkManager, { EffectPlayerView } from '@banuba/react-native';
import React from 'react';
import { Component } from 'react';
import { Button, NativeEventEmitter, View } from 'react-native';
import * as RNFS from 'react-native-fs';
export default class App extends Component {
ep: any;
eventEmitter: NativeEventEmitter;
recording = false;
state = {
recodButtonTitle: 'Tap to record',
};
constructor(props: {} | Readonly<{}>) {
super(props);
BanubaSdkManager.initialize([], 'Client token');
this.ep = React.createRef<typeof EffectPlayerView>();
this.eventEmitter = new NativeEventEmitter(BanubaSdkManager);
this.eventEmitter.addListener('onVideoRecordingStatus', (started) => {
console.log('onVideoRecordingStatus', started);
});
this.eventEmitter.addListener('onVideoRecordingFinished', (success) => {
console.log('onVideoRecordingFinished', success);
});
this.eventEmitter.addListener('onScreenshotReady', (success) => {
console.log('onScreenshotReady', success);
});
}
render(): React.ReactNode {
return (
<View style={{ flex: 1 }}>
<EffectPlayerView style={{ flex: 1 }} ref={this.ep} />
<View
style={{
marginTop: -64,
marginBottom: 32,
}}
>
<Button
onPress={this.onPressVideoRecording}
title={this.state.recodButtonTitle}
/>
</View>
</View>
);
}
componentDidMount(): void {
BanubaSdkManager.attachView(this.ep.current._nativeTag);
BanubaSdkManager.openCamera();
BanubaSdkManager.startPlayer();
BanubaSdkManager.loadEffect('effects/TrollGrandma');
}
componentWillUnmount(): void {
BanubaSdkManager.stopPlayer();
}
onPressVideoRecording = () => {
if (!this.recording) {
BanubaSdkManager.startVideoRecording(
RNFS.DocumentDirectoryPath + '/video.mp4'
);
this.setState({ recodButtonTitle: 'Stop recording' });
} else {
BanubaSdkManager.stopVideoRecording();
this.setState({ recodButtonTitle: 'Tap to record' });
}
this.recording = !this.recording;
};
}