AudioManager.js
1.18 KB
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
import Record from "./Record";
class AudioManager {
startOptions = {
duration: 600000, //默认10分钟
sampleRate: 16000,
numberOfChannels: 1
}
__isRecording = false
__counter = 0
static instance = null;
constructor(onStart, onStop, onError) {
if (AudioManager.instance) {
return AudioManager.instance;
}
this.recorderManager = uni.getRecorderManager()
this.recorderManager.onStart(onStart)
this.recorderManager.onStop(onStop)
this.recorderManager.onError(onError)
this.__record = new Record()
AudioManager.instance = this;
}
start() {
this.__counter++
this.recorderManager.start(this.startOptions)
}
stop() {
this.__counter = 0
this.__isRecording = false
this.recorderManager.stop()
}
onStop(res) {}
get isRecording() {
return this.__isRecording
}
set isRecording(val) {
this.__isRecording = val
}
get counter() {
return this.__counter
}
get record() {
return this.__record
}
onError(err) {}
}
AudioManager.getInstance = () => {
if (!AudioManager.instance) {
AudioManager.instance = new AudioManager();
}
return AudioManager.instance;
};
export default AudioManager