forked from jsierles/react-native-audio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (93 loc) · 3.19 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
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
'use strict';
import React from "react";
import ReactNative, {
NativeModules,
NativeAppEventEmitter,
DeviceEventEmitter,
Platform
} from "react-native";
var AudioRecorderManager = NativeModules.AudioRecorderManager;
var AudioRecorder = {
prepareRecordingAtPath: function(path, options) {
if (this.progressSubscription) this.progressSubscription.remove();
this.progressSubscription = NativeAppEventEmitter.addListener('recordingProgress',
(data) => {
if (this.onProgress) {
this.onProgress(data);
}
}
);
if (this.finishedSubscription) this.finishedSubscription.remove();
this.finishedSubscription = NativeAppEventEmitter.addListener('recordingFinished',
(data) => {
if (this.onFinished) {
this.onFinished(data);
}
}
);
var defaultOptions = {
SampleRate: 44100.0,
Channels: 2,
AudioQuality: 'High',
AudioEncoding: 'ima4',
OutputFormat: 'mpeg_4',
MeteringEnabled: false,
MeasurementMode: false,
AudioEncodingBitRate: 32000,
IncludeBase64: false
};
var recordingOptions = {...defaultOptions, ...options};
if (Platform.OS === 'ios') {
AudioRecorderManager.prepareRecordingAtPath(
path,
recordingOptions.SampleRate,
recordingOptions.Channels,
recordingOptions.AudioQuality,
recordingOptions.AudioEncoding,
recordingOptions.MeteringEnabled,
recordingOptions.MeasurementMode,
recordingOptions.IncludeBase64
);
} else {
return AudioRecorderManager.prepareRecordingAtPath(path, recordingOptions);
}
},
startRecording: function() {
return AudioRecorderManager.startRecording();
},
pauseRecording: function() {
return AudioRecorderManager.pauseRecording();
},
resumeRecording: function() {
return AudioRecorderManager.resumeRecording();
},
stopRecording: function() {
return AudioRecorderManager.stopRecording();
},
checkAuthorizationStatus: AudioRecorderManager.checkAuthorizationStatus,
requestAuthorization: AudioRecorderManager.requestAuthorization,
removeListeners: function() {
if (this.progressSubscription) this.progressSubscription.remove();
if (this.finishedSubscription) this.finishedSubscription.remove();
},
};
let AudioUtils = {};
if (Platform.OS === 'ios') {
AudioUtils = {
MainBundlePath: AudioRecorderManager.MainBundlePath,
CachesDirectoryPath: AudioRecorderManager.NSCachesDirectoryPath,
DocumentDirectoryPath: AudioRecorderManager.NSDocumentDirectoryPath,
LibraryDirectoryPath: AudioRecorderManager.NSLibraryDirectoryPath,
};
} else if (Platform.OS === 'android') {
AudioUtils = {
MainBundlePath: AudioRecorderManager.MainBundlePath,
CachesDirectoryPath: AudioRecorderManager.CachesDirectoryPath,
DocumentDirectoryPath: AudioRecorderManager.DocumentDirectoryPath,
LibraryDirectoryPath: AudioRecorderManager.LibraryDirectoryPath,
PicturesDirectoryPath: AudioRecorderManager.PicturesDirectoryPath,
MusicDirectoryPath: AudioRecorderManager.MusicDirectoryPath,
DownloadsDirectoryPath: AudioRecorderManager.DownloadsDirectoryPath
};
}
module.exports = {AudioRecorder, AudioUtils};