-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.js
66 lines (53 loc) · 1.67 KB
/
audio.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
// @flow
import AudioRecorderPlayer from "react-native-audio-recorder-player";
import { Recorder } from "react-native-audio-toolkit";
export default class AudioRecorder {
audioRecorderPlayer = new AudioRecorderPlayer();
recorder = new Recorder("record.mp4", {
// Set bitrate for the recorder, in bits per second
bitrate: 192000,
// Set number of channels
channels: 2,
// Set how many samples per second
sampleRate: 44100,
// Override format. Possible values:
// Cross-platform: "mp4", "aac"
// Android only: "ogg", "webm", "amr"
format: "mp4",
// Override encoder. Android only.
// Possible values:
// "aac", "mp4", "webm", "ogg", "amr"
encoder: "mp4",
// Quality of the recording, iOS only.
// Possible values: "min", "low", "medium", "high", "max"
quality: "low"
});
onStartRecord = (callback: (err: string, path: string) => {}) => {
this.recorder.prepare((err, fsPath) => {
if (err) {
console.warn("error onStartRecord:", err);
}
callback(err, fsPath);
});
this.recorder.record();
}
onStopRecord = (callback: Function) => {
this.recorder.stop(callback);
}
onStartPlay = async (path: string) => {
const url = await this.audioRecorderPlayer.startPlayer(path);
this.audioRecorderPlayer.addPlayBackListener((e) => {
if (e.current_position === e.duration) {
this.audioRecorderPlayer.stopPlayer();
}
});
return url;
}
onPausePlay = async () => {
await this.audioRecorderPlayer.pausePlayer();
}
onStopPlay = () => {
this.audioRecorderPlayer.stopPlayer();
this.audioRecorderPlayer.removePlayBackListener();
}
}