@react-native-ohos/react-native-audio-recorder-player 3.7.1-beta.1 → 3.7.1
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/LICENSE +20 -20
- package/README.OpenSource +10 -10
- package/README.md +822 -753
- package/harmony/audio_recorder_player/BuildProfile.ets +16 -16
- package/harmony/audio_recorder_player/LICENSE +21 -21
- package/harmony/audio_recorder_player/build-profile.json5 +28 -28
- package/harmony/audio_recorder_player/index.ets +27 -25
- package/harmony/audio_recorder_player/oh-package-lock.json5 +18 -0
- package/harmony/audio_recorder_player/oh-package.json5 +20 -20
- package/harmony/audio_recorder_player/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerPackage.h +48 -48
- package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.cpp +90 -90
- package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.h +35 -35
- package/harmony/audio_recorder_player/src/main/ets/{RNAudioRecorderPlayerPackage.ts → RNAudioRecorderPlayerPackage.ets} +48 -47
- package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +324 -323
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +464 -464
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/types.ts +45 -45
- package/harmony/audio_recorder_player/src/main/ets/index.ts +209 -209
- package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +299 -299
- package/harmony/audio_recorder_player/src/main/ets/recorder/types.ts +61 -61
- package/harmony/audio_recorder_player/src/main/ets/utils/DateTimeUtils.ts +88 -88
- package/harmony/audio_recorder_player/src/main/ets/utils/Logger.ts +45 -45
- package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +105 -105
- package/harmony/audio_recorder_player/src/main/module.json5 +9 -9
- package/harmony/audio_recorder_player/src/main/resources/base/element/string.json +8 -8
- package/harmony/audio_recorder_player/src/main/resources/base/media/ic_public_error.svg +9 -9
- package/harmony/audio_recorder_player/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/audio_recorder_player/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/audio_recorder_player/{ts.ts → ts.ets} +26 -26
- package/harmony/audio_recorder_player.har +0 -0
- package/index.ts +539 -539
- package/package.json +71 -60
- package/src/NativeAudioRecorderPlayerModule.ts +42 -42
|
@@ -1,323 +1,324 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
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
|
-
let
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
dB = Math.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.RecordBackListenerTimer
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.PlayBackListenerTimer
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
media.ContainerFormatType
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
*
|
|
235
|
-
* @
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
*
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
*
|
|
280
|
-
* @
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
*
|
|
292
|
-
* @
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
*
|
|
310
|
-
* @
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { AnyThreadTurboModule, AnyThreadTurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import { media } from '@kit.MediaKit';
|
|
27
|
+
import type { AudioSet } from '.';
|
|
28
|
+
import Recorder from './recorder/Recorder';
|
|
29
|
+
import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, } from './recorder/types';
|
|
30
|
+
import AudioPlayer from './audioPlayer/AudioPlayer';
|
|
31
|
+
import { AVPlayerState, EventTarget, playBackName, processValue, } from './audioPlayer/types';
|
|
32
|
+
import deviceinfo from '@ohos.deviceInfo';
|
|
33
|
+
import Logger from './utils/Logger'
|
|
34
|
+
|
|
35
|
+
export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
36
|
+
public ctx: AnyThreadTurboModuleContext;
|
|
37
|
+
private AVPlayerInstance: AudioPlayer;
|
|
38
|
+
private AVRecorderInstance: Recorder;
|
|
39
|
+
private subscriptionDuration: number = 500;
|
|
40
|
+
private RecordBackListenerTimer;
|
|
41
|
+
private PlayBackListenerTimer;
|
|
42
|
+
private meteringEnabled: boolean = false;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Set listerner from native module for recorder.
|
|
46
|
+
* @returns {callBack((e: RecordBackType): void)}
|
|
47
|
+
*/
|
|
48
|
+
constructor(ctx: AnyThreadTurboModuleContext) {
|
|
49
|
+
super(ctx);
|
|
50
|
+
this.AVRecorderInstance = new Recorder(ctx.uiAbilityContext);
|
|
51
|
+
this.AVPlayerInstance = new AudioPlayer(ctx.uiAbilityContext);
|
|
52
|
+
this.ctx = ctx;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
addListener(eventName: string): void {
|
|
56
|
+
if (eventName === RecordBackName && !this.isRecording()) {
|
|
57
|
+
this.addRecordBackListener();
|
|
58
|
+
}
|
|
59
|
+
if (eventName === playBackName) {
|
|
60
|
+
this.addPlayBackListener();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
removeListeners(count: number): void {
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Remove listener for recorder.
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
public addRecordBackListener(): void {
|
|
72
|
+
if (this.RecordBackListenerTimer) {
|
|
73
|
+
this.removeRecordBackListener();
|
|
74
|
+
}
|
|
75
|
+
this.AVRecorderInstance.onEvent(() => {
|
|
76
|
+
this.RecordBackListenerTimer = setInterval(async () => {
|
|
77
|
+
if (this.meteringEnabled) {
|
|
78
|
+
let maxAmplitude: number = 0;
|
|
79
|
+
let mediaRecorder: Recorder = this.AVRecorderInstance;
|
|
80
|
+
if (mediaRecorder != null) {
|
|
81
|
+
maxAmplitude = await mediaRecorder.getMaxAmplitude();
|
|
82
|
+
}
|
|
83
|
+
let dB: number = -160.0;
|
|
84
|
+
let maxAudioSize: number = 32767.0;
|
|
85
|
+
if (maxAmplitude > 0) {
|
|
86
|
+
dB = 20 * Math.log10(maxAmplitude / maxAudioSize);
|
|
87
|
+
dB = Math.floor(dB);
|
|
88
|
+
}
|
|
89
|
+
this.ctx.rnInstance.emitDeviceEvent(RecordBackName, {
|
|
90
|
+
isRecording: this.AVRecorderInstance.isRecording,
|
|
91
|
+
currentPosition: this.AVRecorderInstance.milliseconds,
|
|
92
|
+
currentMetering: dB,
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
this.ctx.rnInstance.emitDeviceEvent(RecordBackName, {
|
|
96
|
+
isRecording: this.AVRecorderInstance.isRecording,
|
|
97
|
+
currentPosition: this.AVRecorderInstance.milliseconds,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}, this.subscriptionDuration);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Set listener from native module for player.
|
|
106
|
+
* @returns {callBack((e: PlayBackType): void)}
|
|
107
|
+
*/
|
|
108
|
+
public removeRecordBackListener(): void {
|
|
109
|
+
clearInterval(this.RecordBackListenerTimer);
|
|
110
|
+
this.RecordBackListenerTimer = null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* remove listener for player.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
public addPlayBackListener(): void {
|
|
118
|
+
if (this.PlayBackListenerTimer) {
|
|
119
|
+
this.removePlayBackListener();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.AVPlayerInstance.onEvent(EventTarget.timeUpdate, () => {
|
|
123
|
+
this.PlayBackListenerTimer = setInterval(() => {
|
|
124
|
+
this.ctx.rnInstance.emitDeviceEvent(playBackName, {
|
|
125
|
+
isMuted: this.AVPlayerInstance.isMuted,
|
|
126
|
+
isFinished: this.AVPlayerInstance.isFinished,
|
|
127
|
+
currentPosition: this.AVPlayerInstance.currentPosition,
|
|
128
|
+
duration: this.AVPlayerInstance.durationTime,
|
|
129
|
+
});
|
|
130
|
+
if (this.AVPlayerInstance.isFinished) {
|
|
131
|
+
this.stopPlayer();
|
|
132
|
+
}
|
|
133
|
+
}, this.subscriptionDuration);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public removePlayBackListener(): void {
|
|
138
|
+
clearInterval(this.PlayBackListenerTimer);
|
|
139
|
+
this.PlayBackListenerTimer = null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* start recording with param.
|
|
144
|
+
* @param {string} uri audio uri.
|
|
145
|
+
* @returns {Promise<string>}
|
|
146
|
+
*/
|
|
147
|
+
public async startRecorder(
|
|
148
|
+
uri?: string,
|
|
149
|
+
audioSets?: AudioSet,
|
|
150
|
+
meteringEnabled?: boolean,
|
|
151
|
+
): Promise<string> {
|
|
152
|
+
if (this.isRecording()) {
|
|
153
|
+
return Promise.reject(processValue.play);
|
|
154
|
+
}
|
|
155
|
+
this.meteringEnabled = meteringEnabled === true ? true : false;
|
|
156
|
+
const profile: media.AVRecorderProfile = this.getAudioSets(audioSets);
|
|
157
|
+
this.AVRecorderInstance.setAVProfile(profile, audioSets?.AudioSourceHarmony as number as media.AudioSourceType);
|
|
158
|
+
return this.AVRecorderInstance.startRecordingProcess(uri);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getAudioSets(audioSets?: AudioSet): media.AVRecorderProfile {
|
|
162
|
+
let audioCodec: media.CodecMimeType = media.CodecMimeType.AUDIO_AAC;
|
|
163
|
+
if (audioSets?.AudioMimeHarmony) {
|
|
164
|
+
audioCodec = audioSets.AudioMimeHarmony as string as media.CodecMimeType;
|
|
165
|
+
}
|
|
166
|
+
const avProfile: media.AVRecorderProfile = {
|
|
167
|
+
audioBitrate:
|
|
168
|
+
audioSets?.AudioSamplingRateHarmony ||
|
|
169
|
+
defaultBitrate, // 音频比特率
|
|
170
|
+
audioChannels:
|
|
171
|
+
audioSets?.AudioChannelsHarmony ||
|
|
172
|
+
defaultChannels, // 音频声道数
|
|
173
|
+
audioCodec: audioCodec, // 音频编码格式,当前只支持aac、vorbis、flac, 12开始支持AUDIO_MP3
|
|
174
|
+
audioSampleRate:
|
|
175
|
+
audioSets?.AudioSamplingRateHarmony ||
|
|
176
|
+
defaultSampleRate, // 音频采样率
|
|
177
|
+
fileFormat: (audioSets?.AudioFileFormatHarmony as string as media.ContainerFormatType) ||
|
|
178
|
+
media.ContainerFormatType.CFT_MPEG_4A, // 封装格式,当前只支持m4a, 12开始支持CFT_MP3
|
|
179
|
+
};
|
|
180
|
+
return avProfile;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Pause recording.
|
|
185
|
+
* @returns {Promise<string>}
|
|
186
|
+
*/
|
|
187
|
+
public async pauseRecorder(): Promise<string> {
|
|
188
|
+
if (this.AVRecorderInstance.recorderState === AVRecorderState.started) {
|
|
189
|
+
this.removeRecordBackListener();
|
|
190
|
+
return this.AVRecorderInstance.pauseRecordingProcess();
|
|
191
|
+
}
|
|
192
|
+
return Promise.reject(processValue.stateError);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Resume recording.
|
|
197
|
+
* @returns {Promise<string>}
|
|
198
|
+
*/
|
|
199
|
+
public async resumeRecorder(): Promise<string> {
|
|
200
|
+
if (this.AVRecorderInstance.recorderState === AVRecorderState.paused) {
|
|
201
|
+
this.addRecordBackListener();
|
|
202
|
+
return this.AVRecorderInstance.resumeRecordingProcess();
|
|
203
|
+
}
|
|
204
|
+
return Promise.reject(processValue.stateError);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* stop recording.
|
|
209
|
+
* @returns {Promise<string>}
|
|
210
|
+
*/
|
|
211
|
+
public async stopRecorder(): Promise<string> {
|
|
212
|
+
if (
|
|
213
|
+
[AVRecorderState.started, AVRecorderState.paused].includes(
|
|
214
|
+
this.AVRecorderInstance.recorderState,
|
|
215
|
+
)
|
|
216
|
+
) {
|
|
217
|
+
// 仅在started或者paused状态下调用stop为合理状态切换
|
|
218
|
+
this.removeRecordBackListener();
|
|
219
|
+
return this.AVRecorderInstance.stopRecordingProcess();
|
|
220
|
+
}
|
|
221
|
+
return Promise.reject(processValue.stateError);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public async startPlayer(uri?: string, httpHeaders?: Record<string, string>): Promise<string> {
|
|
225
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.paused) {
|
|
226
|
+
return this.resumePlayer();
|
|
227
|
+
}
|
|
228
|
+
const url = await this.AVPlayerInstance.startPlayeringProcess(uri, httpHeaders);
|
|
229
|
+
!!url && this.addPlayBackListener();
|
|
230
|
+
return url;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Start playing with param.
|
|
235
|
+
* @param {string} uri audio uri.
|
|
236
|
+
* @returns {Promise<string>}
|
|
237
|
+
*/
|
|
238
|
+
public async resumePlayer(): Promise<string> {
|
|
239
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.paused) {
|
|
240
|
+
this.addPlayBackListener();
|
|
241
|
+
return this.AVPlayerInstance.resumePlayeringProcess();
|
|
242
|
+
}
|
|
243
|
+
return Promise.reject(processValue.stateError);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Resume playing.
|
|
248
|
+
* @returns {Promise<string>}
|
|
249
|
+
*/
|
|
250
|
+
public async stopPlayer(): Promise<string> {
|
|
251
|
+
this.removePlayBackListener();
|
|
252
|
+
return this.AVPlayerInstance.stopPlayeringProcess();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Stop playing.
|
|
257
|
+
* @returns {Promise<string>}
|
|
258
|
+
*/
|
|
259
|
+
public async pausePlayer(): Promise<string> {
|
|
260
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.playing) {
|
|
261
|
+
this.removePlayBackListener();
|
|
262
|
+
return this.AVPlayerInstance.pausePlayeringProcess();
|
|
263
|
+
}
|
|
264
|
+
return Promise.reject(processValue.stateError);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Pause playing.
|
|
269
|
+
* @returns {Promise<string>}
|
|
270
|
+
*/
|
|
271
|
+
public async seekToPlayer(time: number): Promise<string> {
|
|
272
|
+
if (!this.AVPlayerInstance.seekToPlayer) {
|
|
273
|
+
return Promise.reject(processValue.stateError);
|
|
274
|
+
}
|
|
275
|
+
return this.AVPlayerInstance.seekToPlayer(time);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Seek to.
|
|
280
|
+
* @param {number} time position seek to in millisecond.
|
|
281
|
+
* @returns {Promise<string>}
|
|
282
|
+
*/
|
|
283
|
+
async setVolume(volume: number): Promise<string> {
|
|
284
|
+
if (!this.AVPlayerInstance.setVolume) {
|
|
285
|
+
return Promise.reject(processValue.stateError);
|
|
286
|
+
}
|
|
287
|
+
return this.AVPlayerInstance.setVolume(volume);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Set playback speed.
|
|
292
|
+
* @param {number} playbackSpeed set playback speed.
|
|
293
|
+
* @returns {Promise<string>}
|
|
294
|
+
*/
|
|
295
|
+
async setPlaybackSpeed(playbackSpeed: number): Promise<string> {
|
|
296
|
+
if (!this.AVPlayerInstance.setPlaybackSpeed) {
|
|
297
|
+
return Promise.reject(processValue.stateError);
|
|
298
|
+
}
|
|
299
|
+
let sdkApiVersionInfo: number = deviceinfo.sdkApiVersion;
|
|
300
|
+
Logger.debug("RNAudioRecorderPlayerTurboModule", `playbackSpeed:${playbackSpeed}---apiversion:${sdkApiVersionInfo}`);
|
|
301
|
+
if (playbackSpeed == 3 && sdkApiVersionInfo < 13) {
|
|
302
|
+
Logger.debug("RNAudioRecorderPlayerTurboModule", `apiversion < 13 not supported speed 3`);
|
|
303
|
+
return Promise.reject(processValue.stateError);
|
|
304
|
+
}
|
|
305
|
+
return this.AVPlayerInstance.setPlaybackSpeed(playbackSpeed);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Set volume.
|
|
310
|
+
* @param {number} setVolume set volume.
|
|
311
|
+
* @returns {Promise<string>}
|
|
312
|
+
*/
|
|
313
|
+
async setSubscriptionDuration(sec: number): Promise<string> {
|
|
314
|
+
const milliseconds = sec * 1000;
|
|
315
|
+
this.subscriptionDuration = milliseconds;
|
|
316
|
+
return sec.toString();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private isRecording(): boolean {
|
|
320
|
+
return [AVRecorderState.started, AVRecorderState.paused].includes(
|
|
321
|
+
this.AVRecorderInstance.recorderState,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|