@react-native-ohos/audio-toolkit 2.0.4-rc.1 → 2.0.4-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -136
- package/LICENSE +22 -22
- package/{harmony/audio_toolkit/OAT.xml → OAT.xml} +47 -37
- package/README.md +11 -17
- package/ReactNativeAudioToolkit.podspec +18 -18
- package/harmony/audio_toolkit/build-profile.json5 +7 -7
- package/harmony/audio_toolkit/hvigorfile.ts +1 -1
- package/harmony/audio_toolkit/index.ets +26 -25
- package/harmony/audio_toolkit/oh-package.json5 +12 -12
- package/harmony/audio_toolkit/src/main/cpp/AudioToolkitPackage.h +15 -0
- package/harmony/audio_toolkit/src/main/cpp/CMakeLists.txt +10 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/RNOH/generated/BaseReactNativeAudioToolkitPackage.h +69 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/RNOH/generated/turbo_modules/RCTAudioPlayer.cpp +23 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/RNOH/generated/turbo_modules/RCTAudioPlayer.h +16 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/RNOH/generated/turbo_modules/RCTAudioRecorder.cpp +20 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/RNOH/generated/turbo_modules/RCTAudioRecorder.h +16 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/ComponentDescriptors.h +22 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/EventEmitters.cpp +18 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/EventEmitters.h +19 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/Props.cpp +21 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/Props.h +20 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/ShadowNodes.cpp +19 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/ShadowNodes.h +25 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/States.cpp +18 -0
- package/harmony/audio_toolkit/src/main/cpp/generated/react/renderer/components/react_native_audio_toolkit/States.h +23 -0
- package/harmony/audio_toolkit/src/main/ets/{AudioToolkitPackage.ts → AudioToolkitPackage.ets} +51 -50
- package/harmony/audio_toolkit/src/main/ets/Logger.ts +63 -63
- package/harmony/audio_toolkit/src/main/ets/RNCAudioPlayerTurboModule.ts +432 -432
- package/harmony/audio_toolkit/src/main/ets/RNCAudioRecorderTurboModule.ts +260 -260
- package/harmony/audio_toolkit/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/audio_toolkit/src/main/ets/generated/index.ets +5 -0
- package/harmony/audio_toolkit/src/main/ets/generated/ts.ts +6 -0
- package/harmony/audio_toolkit/src/main/ets/generated/turboModules/RCTAudioPlayer.ts +40 -0
- package/harmony/audio_toolkit/src/main/ets/generated/turboModules/RCTAudioRecorder.ts +24 -0
- package/harmony/audio_toolkit/src/main/ets/generated/turboModules/ts.ts +6 -0
- package/harmony/audio_toolkit/src/main/module.json5 +6 -6
- package/harmony/audio_toolkit/src/main/resources/base/element/string.json +7 -7
- package/harmony/audio_toolkit/src/main/resources/en_US/element/string.json +7 -7
- package/harmony/audio_toolkit/src/main/resources/zh_CN/element/string.json +7 -7
- package/harmony/audio_toolkit/{ts.ts → ts.ets} +25 -25
- package/harmony/audio_toolkit.har +0 -0
- package/package.json +48 -46
- package/src/Player.js +329 -329
- package/src/PlayerModule.ts +51 -51
- package/src/Recorder.js +183 -183
- package/src/RecorderModule.ts +83 -83
- package/src/index.ts +5 -5
- package/harmony/audio_toolkit/BuildProfile.ets +0 -17
- package/harmony/audio_toolkit/LICENSE +0 -21
- package/harmony/audio_toolkit/NOTICE +0 -33
- package/harmony/audio_toolkit/README.OpenSource +0 -11
- package/harmony/audio_toolkit/README.md +0 -230
package/src/PlayerModule.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
3
|
-
TurboModuleRegistry,
|
|
4
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
5
|
-
TurboModule,
|
|
6
|
-
EmitterSubscription,
|
|
7
|
-
NativeEventEmitter,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
10
|
-
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
11
|
-
|
|
12
|
-
enum PlaybackCategories {
|
|
13
|
-
Playback = 1,
|
|
14
|
-
Ambient = 2,
|
|
15
|
-
SoloAmbient = 3
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface Option {
|
|
19
|
-
autoDestroy: boolean;
|
|
20
|
-
continuesToPlayInBackground: boolean;
|
|
21
|
-
category: PlaybackCategories;
|
|
22
|
-
mixWithOthers: boolean;
|
|
23
|
-
}
|
|
24
|
-
interface setOptions {
|
|
25
|
-
volume: string,
|
|
26
|
-
pan: string,
|
|
27
|
-
wakeLock: string,
|
|
28
|
-
looping: boolean,
|
|
29
|
-
speed: boolean,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface PlayInfo {
|
|
33
|
-
duration: number,
|
|
34
|
-
position: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface Spec extends TurboModule {
|
|
38
|
-
set(playerId: number, option: setOptions, next: () => void): void;
|
|
39
|
-
prepare(playerId: number, path: string, option: Option, next: () => void): void;
|
|
40
|
-
play(playerId: number, next: () => void): void;
|
|
41
|
-
pause(): void;
|
|
42
|
-
stop(): void;
|
|
43
|
-
destroy(content: string): void;
|
|
44
|
-
seek(): void;
|
|
45
|
-
getCurrentTime(playerId: number, callback: (err: string, result?: PlayInfo) => void): void
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const RCTAudioPlayer =
|
|
49
|
-
TurboModuleRegistry.getEnforcing<Spec>('RCTAudioPlayer');
|
|
50
|
-
|
|
51
|
-
export default RCTAudioPlayer;
|
|
1
|
+
import {
|
|
2
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
3
|
+
TurboModuleRegistry,
|
|
4
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
5
|
+
TurboModule,
|
|
6
|
+
EmitterSubscription,
|
|
7
|
+
NativeEventEmitter,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
10
|
+
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
11
|
+
|
|
12
|
+
enum PlaybackCategories {
|
|
13
|
+
Playback = 1,
|
|
14
|
+
Ambient = 2,
|
|
15
|
+
SoloAmbient = 3
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Option {
|
|
19
|
+
autoDestroy: boolean;
|
|
20
|
+
continuesToPlayInBackground: boolean;
|
|
21
|
+
category: PlaybackCategories;
|
|
22
|
+
mixWithOthers: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface setOptions {
|
|
25
|
+
volume: string,
|
|
26
|
+
pan: string,
|
|
27
|
+
wakeLock: string,
|
|
28
|
+
looping: boolean,
|
|
29
|
+
speed: boolean,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface PlayInfo {
|
|
33
|
+
duration: number,
|
|
34
|
+
position: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Spec extends TurboModule {
|
|
38
|
+
set(playerId: number, option: setOptions, next: () => void): void;
|
|
39
|
+
prepare(playerId: number, path: string, option: Option, next: () => void): void;
|
|
40
|
+
play(playerId: number, next: () => void): void;
|
|
41
|
+
pause(): void;
|
|
42
|
+
stop(): void;
|
|
43
|
+
destroy(content: string): void;
|
|
44
|
+
seek(): void;
|
|
45
|
+
getCurrentTime(playerId: number, callback: (err: string, result?: PlayInfo) => void): void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const RCTAudioPlayer =
|
|
49
|
+
TurboModuleRegistry.getEnforcing<Spec>('RCTAudioPlayer');
|
|
50
|
+
|
|
51
|
+
export default RCTAudioPlayer;
|
package/src/Recorder.js
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
import {
|
|
3
|
-
NativeAppEventEmitter,
|
|
4
|
-
DeviceEventEmitter
|
|
5
|
-
} from 'react-native'
|
|
6
|
-
import RCTAudioRecorder from './RecorderModule'
|
|
7
|
-
import async from 'async';
|
|
8
|
-
import EventEmitter from 'eventemitter3';
|
|
9
|
-
import MediaStates from '@react-native-community/audio-toolkit/src/MediaStates';
|
|
10
|
-
|
|
11
|
-
// Only import specific items from lodash to keep build size down
|
|
12
|
-
import noop from 'lodash/noop';
|
|
13
|
-
|
|
14
|
-
var recorderId = 0;
|
|
15
|
-
|
|
16
|
-
var defaultRecorderOptions = {
|
|
17
|
-
autoDestroy: true
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Represents a media recorder
|
|
22
|
-
* @constructor
|
|
23
|
-
*/
|
|
24
|
-
class Recorder extends EventEmitter {
|
|
25
|
-
constructor(path, options = defaultRecorderOptions) {
|
|
26
|
-
super();
|
|
27
|
-
|
|
28
|
-
this._path = path;
|
|
29
|
-
this._options = options;
|
|
30
|
-
|
|
31
|
-
this._recorderId = recorderId++;
|
|
32
|
-
this._reset();
|
|
33
|
-
|
|
34
|
-
let appEventEmitter = Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter;
|
|
35
|
-
|
|
36
|
-
appEventEmitter.addListener('RCTAudioRecorderEvent:' + this._recorderId, (payload: Event) => {
|
|
37
|
-
this._handleEvent(payload.event, payload.data);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_reset() {
|
|
42
|
-
this._state = MediaStates.IDLE;
|
|
43
|
-
this._duration = -1;
|
|
44
|
-
this._position = -1;
|
|
45
|
-
this._lastSync = -1;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_updateState(err, state) {
|
|
49
|
-
this._state = err ? MediaStates.ERROR : state;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_handleEvent(event, data) {
|
|
53
|
-
switch (event) {
|
|
54
|
-
case 'ended':
|
|
55
|
-
this._state = Math.min(this._state, MediaStates.PREPARED);
|
|
56
|
-
break;
|
|
57
|
-
case 'info':
|
|
58
|
-
// TODO
|
|
59
|
-
break;
|
|
60
|
-
case 'error':
|
|
61
|
-
this._reset();
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.emit(event, data);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
prepare(callback = noop) {
|
|
69
|
-
if (Platform.OS !== 'harmony') {
|
|
70
|
-
this._updateState(null, MediaStates.PREPARING);
|
|
71
|
-
// Prepare recorder
|
|
72
|
-
RCTAudioRecorder.prepare(this._recorderId, this._path, this._options, (err, fsPath) => {
|
|
73
|
-
this._fsPath = fsPath;
|
|
74
|
-
this._updateState(err, MediaStates.PREPARED);
|
|
75
|
-
callback(err, fsPath);
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
RCTAudioRecorder.prepare(this._recorderId, this._path, this._options, (err, fsPath) => {
|
|
79
|
-
this._fsPath = fsPath;
|
|
80
|
-
this._updateState(err, MediaStates.PREPARED);
|
|
81
|
-
callback(err, fsPath);
|
|
82
|
-
}, (err) => {
|
|
83
|
-
this._updateState(err, MediaStates.PREPARING);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
record(callback = noop) {
|
|
90
|
-
let tasks = [];
|
|
91
|
-
// Make sure recorder is prepared
|
|
92
|
-
if (this._state === MediaStates.IDLE) {
|
|
93
|
-
tasks.push((next) => {
|
|
94
|
-
this.prepare((err, fsPath) => {
|
|
95
|
-
this.harmonyPrepareCallBack(err, fsPath, callback);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
// Start recording
|
|
100
|
-
tasks.push((next) => {
|
|
101
|
-
RCTAudioRecorder.record(this._recorderId, next);
|
|
102
|
-
});
|
|
103
|
-
async.series(tasks, (err) => {
|
|
104
|
-
if (Platform.OS !== 'harmony') {
|
|
105
|
-
this._updateState(err, MediaStates.RECORDING);
|
|
106
|
-
callback(err);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (this._state === MediaStates.PAUSED) {
|
|
110
|
-
this._updateState(err, MediaStates.RECORDING);
|
|
111
|
-
callback(err);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
harmonyPrepareCallBack(err, fsPath, callback = noop) {
|
|
118
|
-
if (Platform.OS !== 'harmony') {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (fsPath) {
|
|
122
|
-
this._updateState(err, MediaStates.RECORDING);
|
|
123
|
-
callback(err, fsPath);
|
|
124
|
-
} else {
|
|
125
|
-
this._updateState(err, MediaStates.IDLE);
|
|
126
|
-
callback(err, null);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
stop(callback = noop) {
|
|
131
|
-
if (this._state >= MediaStates.RECORDING) {
|
|
132
|
-
RCTAudioRecorder.stop(this._recorderId, (err) => {
|
|
133
|
-
this._updateState(err, MediaStates.DESTROYED);
|
|
134
|
-
callback(err);
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
setTimeout(callback, 0);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
pause(callback = noop) {
|
|
144
|
-
if (this._state >= MediaStates.RECORDING) {
|
|
145
|
-
RCTAudioRecorder.pause(this._recorderId, (err) => {
|
|
146
|
-
this._updateState(err, MediaStates.PAUSED);
|
|
147
|
-
callback(err);
|
|
148
|
-
});
|
|
149
|
-
} else {
|
|
150
|
-
setTimeout(callback, 0);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
toggleRecord(callback = noop) {
|
|
157
|
-
if (this._state === MediaStates.RECORDING) {
|
|
158
|
-
this.stop((err) => {
|
|
159
|
-
callback(err, true);
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
this.record((err) => {
|
|
163
|
-
callback(err,false);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
destroy(callback = noop) {
|
|
171
|
-
this._reset();
|
|
172
|
-
RCTAudioRecorder.destroy(this._recorderId, callback);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
get state() { return this._state; }
|
|
176
|
-
get canRecord() { return this._state >= MediaStates.PREPARED; }
|
|
177
|
-
get canPrepare() { return this._state == MediaStates.IDLE; }
|
|
178
|
-
get isRecording() { return this._state == MediaStates.RECORDING; }
|
|
179
|
-
get isPrepared() { return this._state == MediaStates.PREPARED; }
|
|
180
|
-
get fsPath() { return this._fsPath; }
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default Recorder;
|
|
1
|
+
'use strict';
|
|
2
|
+
import {
|
|
3
|
+
NativeAppEventEmitter,
|
|
4
|
+
DeviceEventEmitter
|
|
5
|
+
} from 'react-native'
|
|
6
|
+
import RCTAudioRecorder from './RecorderModule'
|
|
7
|
+
import async from 'async';
|
|
8
|
+
import EventEmitter from 'eventemitter3';
|
|
9
|
+
import MediaStates from '@react-native-community/audio-toolkit/src/MediaStates';
|
|
10
|
+
|
|
11
|
+
// Only import specific items from lodash to keep build size down
|
|
12
|
+
import noop from 'lodash/noop';
|
|
13
|
+
|
|
14
|
+
var recorderId = 0;
|
|
15
|
+
|
|
16
|
+
var defaultRecorderOptions = {
|
|
17
|
+
autoDestroy: true
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents a media recorder
|
|
22
|
+
* @constructor
|
|
23
|
+
*/
|
|
24
|
+
class Recorder extends EventEmitter {
|
|
25
|
+
constructor(path, options = defaultRecorderOptions) {
|
|
26
|
+
super();
|
|
27
|
+
|
|
28
|
+
this._path = path;
|
|
29
|
+
this._options = options;
|
|
30
|
+
|
|
31
|
+
this._recorderId = recorderId++;
|
|
32
|
+
this._reset();
|
|
33
|
+
|
|
34
|
+
let appEventEmitter = Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter;
|
|
35
|
+
|
|
36
|
+
appEventEmitter.addListener('RCTAudioRecorderEvent:' + this._recorderId, (payload: Event) => {
|
|
37
|
+
this._handleEvent(payload.event, payload.data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_reset() {
|
|
42
|
+
this._state = MediaStates.IDLE;
|
|
43
|
+
this._duration = -1;
|
|
44
|
+
this._position = -1;
|
|
45
|
+
this._lastSync = -1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_updateState(err, state) {
|
|
49
|
+
this._state = err ? MediaStates.ERROR : state;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_handleEvent(event, data) {
|
|
53
|
+
switch (event) {
|
|
54
|
+
case 'ended':
|
|
55
|
+
this._state = Math.min(this._state, MediaStates.PREPARED);
|
|
56
|
+
break;
|
|
57
|
+
case 'info':
|
|
58
|
+
// TODO
|
|
59
|
+
break;
|
|
60
|
+
case 'error':
|
|
61
|
+
this._reset();
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.emit(event, data);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
prepare(callback = noop) {
|
|
69
|
+
if (Platform.OS !== 'harmony') {
|
|
70
|
+
this._updateState(null, MediaStates.PREPARING);
|
|
71
|
+
// Prepare recorder
|
|
72
|
+
RCTAudioRecorder.prepare(this._recorderId, this._path, this._options, (err, fsPath) => {
|
|
73
|
+
this._fsPath = fsPath;
|
|
74
|
+
this._updateState(err, MediaStates.PREPARED);
|
|
75
|
+
callback(err, fsPath);
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
RCTAudioRecorder.prepare(this._recorderId, this._path, this._options, (err, fsPath) => {
|
|
79
|
+
this._fsPath = fsPath;
|
|
80
|
+
this._updateState(err, MediaStates.PREPARED);
|
|
81
|
+
callback(err, fsPath);
|
|
82
|
+
}, (err) => {
|
|
83
|
+
this._updateState(err, MediaStates.PREPARING);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
record(callback = noop) {
|
|
90
|
+
let tasks = [];
|
|
91
|
+
// Make sure recorder is prepared
|
|
92
|
+
if (this._state === MediaStates.IDLE) {
|
|
93
|
+
tasks.push((next) => {
|
|
94
|
+
this.prepare((err, fsPath) => {
|
|
95
|
+
this.harmonyPrepareCallBack(err, fsPath, callback);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Start recording
|
|
100
|
+
tasks.push((next) => {
|
|
101
|
+
RCTAudioRecorder.record(this._recorderId, next);
|
|
102
|
+
});
|
|
103
|
+
async.series(tasks, (err) => {
|
|
104
|
+
if (Platform.OS !== 'harmony') {
|
|
105
|
+
this._updateState(err, MediaStates.RECORDING);
|
|
106
|
+
callback(err);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (this._state === MediaStates.PAUSED) {
|
|
110
|
+
this._updateState(err, MediaStates.RECORDING);
|
|
111
|
+
callback(err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
harmonyPrepareCallBack(err, fsPath, callback = noop) {
|
|
118
|
+
if (Platform.OS !== 'harmony') {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (fsPath) {
|
|
122
|
+
this._updateState(err, MediaStates.RECORDING);
|
|
123
|
+
callback(err, fsPath);
|
|
124
|
+
} else {
|
|
125
|
+
this._updateState(err, MediaStates.IDLE);
|
|
126
|
+
callback(err, null);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
stop(callback = noop) {
|
|
131
|
+
if (this._state >= MediaStates.RECORDING) {
|
|
132
|
+
RCTAudioRecorder.stop(this._recorderId, (err) => {
|
|
133
|
+
this._updateState(err, MediaStates.DESTROYED);
|
|
134
|
+
callback(err);
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
setTimeout(callback, 0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
pause(callback = noop) {
|
|
144
|
+
if (this._state >= MediaStates.RECORDING) {
|
|
145
|
+
RCTAudioRecorder.pause(this._recorderId, (err) => {
|
|
146
|
+
this._updateState(err, MediaStates.PAUSED);
|
|
147
|
+
callback(err);
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
setTimeout(callback, 0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
toggleRecord(callback = noop) {
|
|
157
|
+
if (this._state === MediaStates.RECORDING) {
|
|
158
|
+
this.stop((err) => {
|
|
159
|
+
callback(err, true);
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
this.record((err) => {
|
|
163
|
+
callback(err,false);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
destroy(callback = noop) {
|
|
171
|
+
this._reset();
|
|
172
|
+
RCTAudioRecorder.destroy(this._recorderId, callback);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get state() { return this._state; }
|
|
176
|
+
get canRecord() { return this._state >= MediaStates.PREPARED; }
|
|
177
|
+
get canPrepare() { return this._state == MediaStates.IDLE; }
|
|
178
|
+
get isRecording() { return this._state == MediaStates.RECORDING; }
|
|
179
|
+
get isPrepared() { return this._state == MediaStates.PREPARED; }
|
|
180
|
+
get fsPath() { return this._fsPath; }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default Recorder;
|
package/src/RecorderModule.ts
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
3
|
-
TurboModuleRegistry,
|
|
4
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
5
|
-
TurboModule,
|
|
6
|
-
} from 'react-native';
|
|
7
|
-
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
8
|
-
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
9
|
-
|
|
10
|
-
interface RecorderOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Set bitrate for the recorder, in bits per second (Default: 128000)
|
|
13
|
-
*/
|
|
14
|
-
bitrate: number;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Set number of channels (Default: 2)
|
|
18
|
-
*/
|
|
19
|
-
channels: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Set how many samples per second (Default: 44100)
|
|
23
|
-
*/
|
|
24
|
-
sampleRate: number;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Override format. Possible values:
|
|
28
|
-
* - Cross-platform: 'mp4', 'aac'
|
|
29
|
-
* - Android only: 'ogg', 'webm', 'amr'
|
|
30
|
-
*
|
|
31
|
-
* (Default: based on filename extension)
|
|
32
|
-
*/
|
|
33
|
-
format: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Override encoder. Android only.
|
|
37
|
-
*
|
|
38
|
-
* Possible values: 'aac', 'mp4', 'webm', 'ogg', 'amr'
|
|
39
|
-
*
|
|
40
|
-
* (Default: based on filename extension)
|
|
41
|
-
*/
|
|
42
|
-
encoder: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Quality of the recording, iOS only.
|
|
46
|
-
*
|
|
47
|
-
* Possible values: 'min', 'low', 'medium', 'high', 'max'
|
|
48
|
-
*
|
|
49
|
-
* (Default: 'medium')
|
|
50
|
-
*/
|
|
51
|
-
quality: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface Event {
|
|
55
|
-
event: string;
|
|
56
|
-
data: string | null | undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface Spec extends TurboModule {
|
|
60
|
-
/**
|
|
61
|
-
* Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
62
|
-
* ```javascript
|
|
63
|
-
* async _getContent() {
|
|
64
|
-
* var content = await Clipboard.getString();
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
// 准备
|
|
69
|
-
prepare(recorderId: number, path: string, option: RecorderOptions, next: () => void): void;
|
|
70
|
-
// 开始
|
|
71
|
-
record(recorderId: number, next: () => void): void;
|
|
72
|
-
// 停止
|
|
73
|
-
stop(recorderId: number, next: () => void): void;
|
|
74
|
-
// 暂停
|
|
75
|
-
pause(recorderId: number, next: () => void): void;
|
|
76
|
-
// 销毁
|
|
77
|
-
destroy(recorderId: number, next: () => void): void;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const RCTAudioRecorder =
|
|
81
|
-
TurboModuleRegistry.getEnforcing<Spec>('RCTAudioRecorder');
|
|
82
|
-
|
|
83
|
-
export default RCTAudioRecorder;
|
|
1
|
+
import {
|
|
2
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
3
|
+
TurboModuleRegistry,
|
|
4
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
5
|
+
TurboModule,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
8
|
+
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
9
|
+
|
|
10
|
+
interface RecorderOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Set bitrate for the recorder, in bits per second (Default: 128000)
|
|
13
|
+
*/
|
|
14
|
+
bitrate: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set number of channels (Default: 2)
|
|
18
|
+
*/
|
|
19
|
+
channels: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set how many samples per second (Default: 44100)
|
|
23
|
+
*/
|
|
24
|
+
sampleRate: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Override format. Possible values:
|
|
28
|
+
* - Cross-platform: 'mp4', 'aac'
|
|
29
|
+
* - Android only: 'ogg', 'webm', 'amr'
|
|
30
|
+
*
|
|
31
|
+
* (Default: based on filename extension)
|
|
32
|
+
*/
|
|
33
|
+
format: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Override encoder. Android only.
|
|
37
|
+
*
|
|
38
|
+
* Possible values: 'aac', 'mp4', 'webm', 'ogg', 'amr'
|
|
39
|
+
*
|
|
40
|
+
* (Default: based on filename extension)
|
|
41
|
+
*/
|
|
42
|
+
encoder: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Quality of the recording, iOS only.
|
|
46
|
+
*
|
|
47
|
+
* Possible values: 'min', 'low', 'medium', 'high', 'max'
|
|
48
|
+
*
|
|
49
|
+
* (Default: 'medium')
|
|
50
|
+
*/
|
|
51
|
+
quality: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface Event {
|
|
55
|
+
event: string;
|
|
56
|
+
data: string | null | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Spec extends TurboModule {
|
|
60
|
+
/**
|
|
61
|
+
* Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
62
|
+
* ```javascript
|
|
63
|
+
* async _getContent() {
|
|
64
|
+
* var content = await Clipboard.getString();
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
// 准备
|
|
69
|
+
prepare(recorderId: number, path: string, option: RecorderOptions, next: () => void): void;
|
|
70
|
+
// 开始
|
|
71
|
+
record(recorderId: number, next: () => void): void;
|
|
72
|
+
// 停止
|
|
73
|
+
stop(recorderId: number, next: () => void): void;
|
|
74
|
+
// 暂停
|
|
75
|
+
pause(recorderId: number, next: () => void): void;
|
|
76
|
+
// 销毁
|
|
77
|
+
destroy(recorderId: number, next: () => void): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const RCTAudioRecorder =
|
|
81
|
+
TurboModuleRegistry.getEnforcing<Spec>('RCTAudioRecorder');
|
|
82
|
+
|
|
83
|
+
export default RCTAudioRecorder;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Player, { PlaybackCategories } from './Player';
|
|
2
|
-
import Recorder from './Recorder';
|
|
3
|
-
import MediaStates from '@react-native-community/audio-toolkit/src/MediaStates';
|
|
4
|
-
|
|
5
|
-
export { Player, Recorder, MediaStates, PlaybackCategories };
|
|
1
|
+
import Player, { PlaybackCategories } from './Player';
|
|
2
|
+
import Recorder from './Recorder';
|
|
3
|
+
import MediaStates from '@react-native-community/audio-toolkit/src/MediaStates';
|
|
4
|
+
|
|
5
|
+
export { Player, Recorder, MediaStates, PlaybackCategories };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
|
-
*/
|
|
4
|
-
export const HAR_VERSION = '2.0.3-0.0.2';
|
|
5
|
-
export const BUILD_MODE_NAME = 'debug';
|
|
6
|
-
export const DEBUG = true;
|
|
7
|
-
export const TARGET_NAME = 'default';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* BuildProfile Class is used only for compatibility purposes.
|
|
11
|
-
*/
|
|
12
|
-
export default class BuildProfile {
|
|
13
|
-
static readonly HAR_VERSION = HAR_VERSION;
|
|
14
|
-
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
|
|
15
|
-
static readonly DEBUG = DEBUG;
|
|
16
|
-
static readonly TARGET_NAME = TARGET_NAME;
|
|
17
|
-
}
|