-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
79 lines (74 loc) · 1.74 KB
/
index.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
import React, {
PropTypes
} from 'react';
import {
NativeModules,
NativeEventEmitter,
DeviceEventEmitter,
Platform,
} from 'react-native';
//本地对象
let TIMAudioRecorder = NativeModules.AudioRecorder;
const listener = Platform.OS == 'ios'?new NativeEventEmitter(TIMAudioRecorder):DeviceEventEmitter;
let instance = null;
class Recoder {
static audioUpdaterListener;
static peakInfo;
constructor(){
if(!instance){
this.parpreRecoder = this.parpreRecoder.bind(this);
this.play = this.play.bind(this);
this.stopRecorder = this.stopRecorder.bind(this);
this.startRecorder = this.startRecorder.bind(this);
this.deleteCurrentRecord = this.deleteCurrentRecord.bind(this);
this.peakInfo = {
recordPeak:0,
recordDB:0,
};
this.audioUpdaterListener = listener;
this.listener=listener.addListener('onUpdateRecordPeak',(message)=>{
this.peakInfo = message;
});
instance = this;
}
return instance;
}
/**
* 准备录音
*/
parpreRecoder(){
return TIMAudioRecorder.parpreRecoder();
}
/**
* 开始录音
*/
startRecorder(callback){
TIMAudioRecorder.startRecorder(callback);
}
/**
* 停止录音
*/
stopRecorder(callback){
TIMAudioRecorder.stopRecorder(callback);
}
/**
* 删除当前录制的录音
*/
deleteCurrentRecord(callback){
TIMAudioRecorder.deleteRecord(null,callback);
}
/**
* 播放音乐
*/
play(path,callback){
TIMAudioRecorder.play(path,callback);
}
}
// let AudioRecorder = {
// audioUpdaterListener:listener,
// startRecorder:startRecorder,
// stopRecorder:stopRecorder,
// }
// module.exports = AudioRecorder;
// module.exports = Recoder;
export default Recoder;