forked from prscX/react-native-voice-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNVoiceRecorder.js
51 lines (41 loc) · 1.07 KB
/
RNVoiceRecorder.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
import React, { PureComponent } from "react";
import { ViewPropTypes, NativeModules, Platform } from "react-native";
import PropTypes from "prop-types";
const { RNVoiceRecorder } = NativeModules;
class VoiceRecorder extends PureComponent {
static propTypes = {
...ViewPropTypes,
path: PropTypes.string,
format: PropTypes.string,
onCancel: PropTypes.func,
onDone: PropTypes.func
};
static defaultProps = {
format: 'm4a'
};
static Record(props) {
if (props.format === undefined) props.format = VoiceRecorder.defaultProps.format
RNVoiceRecorder.Record(
props,
(path) => {
props.onDone && props.onDone(path);
},
() => {
props.onCancel && props.onCancel();
}
);
}
static Play(props) {
if (props.format === undefined) props.format = VoiceRecorder.defaultProps.format;
RNVoiceRecorder.Play(
props,
() => {
props.onDone && props.onDone();
},
() => {
props.onCancel && props.onCancel();
}
);
}
}
export { VoiceRecorder as RNVoiceRecorder };