forked from CommercialTribe/react-native-screcorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder.ios.js
148 lines (119 loc) · 3.3 KB
/
recorder.ios.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
import React, {PropTypes} from 'react';
var {
StyleSheet,
requireNativeComponent,
NativeModules,
View,
merge
} = require('react-native');
merge = merge || require('merge');
/******* ENUM **********/
var constants = {
// Flash enum
SCFlashModeOff: 0,
SCFlashModeOn: 1,
SCFlashModeAuto: 2,
SCFlashModeLight: 3
};
/******* STYLES **********/
var styles = StyleSheet.create({
wrapper: {
flex: 1,
backgroundColor: "transparent"
}
});
/******* RECORDER COMPONENT **********/
var Recorder = React.createClass({
propTypes: {
config: PropTypes.object,
device: PropTypes.string,
onNewSegment: PropTypes.func
},
getInitialState() {
return {
recording: false
};
},
/*** PUBLIC METHODS ***/
// Start recording of the current session
record() {
if (this.state.recording) return;
this.state.recording = true;
NativeModules.RNRecorderManager.record();
},
// Capture a picture
capture(callback) {
NativeModules.RNRecorderManager.capture(callback);
},
// Pause recording of the current session
pause() {
if (!this.state.recording) return;
var onNewSegment = this.props.onNewSegment || function() {};
NativeModules.RNRecorderManager.pause(onNewSegment);
this.state.recording = false;
},
// Save the recording
save(callback) {
NativeModules.RNRecorderManager.save(callback);
},
// Remove last segment of the session
removeLastSegment() {
NativeModules.RNRecorderManager.removeLastSegment();
},
// Remove all segments of the session
removeAllSegments() {
NativeModules.RNRecorderManager.removeAllSegments();
},
// Remove segment at the specified index
removeSegmentAtIndex(index) {
NativeModules.RNRecorderManager.removeSegmentAtIndex(index);
},
/*** RENDER ***/
render() {
var config = merge({
autoSetVideoOrientation: false,
flashMode: constants.SCFlashModeOff,
video: {
enabled: true,
bitrate: 2000000, // 2Mbit/s
timescale: 1, // Higher than 1 makes a slow motion, between 0 and 1 makes a timelapse effect
format: "MPEG4",
quality: "HighestQuality", // HighestQuality || MediumQuality || LowQuality
filters: [
/*{
"CIfilter": "CIColorControls",
"animations": [{
"name": "inputSaturation",
"startValue": 100,
"endValue": 0,
"startTime": 0,
"duration": 0.5
}]
},*/
/*{"file": "b_filter"},*/
/*{"CIfilter":"CIColorControls", "inputSaturation": 0},
{"CIfilter":"CIExposureAdjust", "inputEV": 0.7}*/
]
},
audio: {
enabled: true,
bitrate: 128000, // 128kbit/s
channelsCount: 1, // Mono output
format: "MPEG4AAC",
quality: "HighestQuality" // HighestQuality || MediumQuality || LowQuality
}
},this.props.config);
var nativeProps = merge({}, this.props, {
config: config,
device: this.props.device || "front"
});
return (
<RNRecorder {...nativeProps}>
<View style={styles.wrapper}>{this.props.children}</View>
</RNRecorder>
);
}
});
var RNRecorder = requireNativeComponent('RNRecorder', Recorder);
Recorder.constants = constants;
module.exports = Recorder;