forked from jsierles/react-native-audio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (86 loc) · 2.97 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
'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,
AudioEncodingBitRate: 32000
};
var recordingOptions = {...defaultOptions, ...options};
if (Platform.OS === 'ios') {
AudioRecorderManager.prepareRecordingAtPath(
path,
recordingOptions.SampleRate,
recordingOptions.Channels,
recordingOptions.AudioQuality,
recordingOptions.AudioEncoding,
recordingOptions.MeteringEnabled
);
} else {
return AudioRecorderManager.prepareRecordingAtPath(path, recordingOptions);
}
},
startRecording: function() {
return AudioRecorderManager.startRecording();
},
pauseRecording: function() {
return AudioRecorderManager.pauseRecording();
},
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};