-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathrecorder.ios.js
143 lines (122 loc) · 3.37 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
import React, { Component, PropTypes } from 'react';
import {
StyleSheet,
requireNativeComponent,
NativeModules,
View,
} from 'react-native';
import merge from 'merge';
const constants = {
// Flash enum
SCFlashModeOff: 0,
SCFlashModeOn: 1,
SCFlashModeAuto: 2,
SCFlashModeLight: 3
}
/******* STYLES **********/
const styles = StyleSheet.create({
wrapper: {
flex: 1,
backgroundColor: "transparent"
}
});
/******* RECORDER COMPONENT **********/
export default class Recorder extends Component {
constructor(props) {
super(props)
this.state = {
recording: false
}
}
static constants = constants;
static propTypes = {
config: PropTypes.object,
device: PropTypes.string,
flashMode: PropTypes.number,
onNewSegment: PropTypes.func
}
/*** PUBLIC METHODS ***/
// Start recording of the current session
record() {
if (this.state.recording) return;
this.setState({
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.setState({
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() {
const config = merge({
autoSetVideoOrientation: false,
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);
const nativeProps = merge({}, this.props, {
config: config,
device: this.props.device || "front",
flashMode: this.props.flashMode || constants.SCFlashModeOff,
});
return (
<RNRecorder {...nativeProps}>
<View style={styles.wrapper}>{this.props.children}</View>
</RNRecorder>
);
}
}
const RNRecorder = requireNativeComponent('RNRecorder', Recorder);