@react-native-ohos/react-native-audio-recorder-player 3.6.11 → 3.6.13-beta.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +899 -14
- package/harmony/audio_recorder_player/BuildProfile.ets +17 -0
- package/harmony/audio_recorder_player/LICENSE +21 -21
- package/harmony/audio_recorder_player/ResourceTable.txt +1 -1
- package/harmony/audio_recorder_player/build-profile.json5 +28 -28
- package/harmony/audio_recorder_player/index.ets +27 -26
- package/harmony/audio_recorder_player/oh-package-lock.json5 +29 -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 +52 -52
- package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.cpp +92 -92
- package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.h +37 -37
- package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerPackage.ets +48 -48
- package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +316 -310
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +420 -414
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/types.ts +43 -43
- package/harmony/audio_recorder_player/src/main/ets/index.d.ts +209 -209
- package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +305 -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 +101 -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.ets +26 -26
- package/harmony/audio_recorder_player.har +0 -0
- package/index.d.ts +227 -227
- package/index.ts +530 -525
- package/package.json +82 -68
- package/src/NativeAudioRecorderPlayerModule.ts +41 -41
|
@@ -1,310 +1,316 @@
|
|
|
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
|
-
import { TurboModule, TurboModuleContext, } from '@rnoh/react-native-openharmony/ts';
|
|
25
|
-
import { media } from '@kit.MediaKit';
|
|
26
|
-
import {
|
|
27
|
-
import Recorder from './recorder/Recorder';
|
|
28
|
-
import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, } from './recorder/types';
|
|
29
|
-
import AudioPlayer from './audioPlayer/AudioPlayer';
|
|
30
|
-
import { AVPlayerState, EventTarget, playBackName, processValue, } from './audioPlayer/types';
|
|
31
|
-
import { deviceInfo } from '@kit.BasicServicesKit';
|
|
32
|
-
|
|
33
|
-
export class RNAudioRecorderPlayerTurboModule extends TurboModule {
|
|
34
|
-
public ctx: TurboModuleContext;
|
|
35
|
-
private AVPlayerInstance: AudioPlayer;
|
|
36
|
-
private AVRecorderInstance: Recorder;
|
|
37
|
-
private subscriptionDuration: number = 500;
|
|
38
|
-
private RecordBackListenerTimer;
|
|
39
|
-
private PlayBackListenerTimer;
|
|
40
|
-
private meteringEnabled: boolean = false;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
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
|
-
let
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
this.PlayBackListenerTimer
|
|
138
|
-
|
|
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
|
-
|
|
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
|
-
return
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
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
|
+
import { TurboModule, TurboModuleContext, } from '@rnoh/react-native-openharmony/ts';
|
|
25
|
+
import { media } from '@kit.MediaKit';
|
|
26
|
+
import type { AudioSet } from '.';
|
|
27
|
+
import Recorder from './recorder/Recorder';
|
|
28
|
+
import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, processValue as recorderProcessValue } from './recorder/types';
|
|
29
|
+
import AudioPlayer from './audioPlayer/AudioPlayer';
|
|
30
|
+
import { AVPlayerState, EventTarget, playBackName, processValue, } from './audioPlayer/types';
|
|
31
|
+
import { deviceInfo } from '@kit.BasicServicesKit';
|
|
32
|
+
|
|
33
|
+
export class RNAudioRecorderPlayerTurboModule extends TurboModule {
|
|
34
|
+
public ctx: TurboModuleContext;
|
|
35
|
+
private AVPlayerInstance: AudioPlayer;
|
|
36
|
+
private AVRecorderInstance: Recorder;
|
|
37
|
+
private subscriptionDuration: number = 500;
|
|
38
|
+
private RecordBackListenerTimer;
|
|
39
|
+
private PlayBackListenerTimer;
|
|
40
|
+
private meteringEnabled: boolean = false;
|
|
41
|
+
|
|
42
|
+
constructor(ctx: TurboModuleContext) {
|
|
43
|
+
super(ctx);
|
|
44
|
+
this.AVRecorderInstance = new Recorder(ctx.uiAbilityContext);
|
|
45
|
+
this.AVPlayerInstance = new AudioPlayer(ctx.uiAbilityContext);
|
|
46
|
+
this.ctx = ctx;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
addListener(eventName: string): void {
|
|
50
|
+
if (eventName === RecordBackName && !this.isRecording()) {
|
|
51
|
+
this.addRecordBackListener();
|
|
52
|
+
}
|
|
53
|
+
if (eventName === playBackName) {
|
|
54
|
+
this.addPlayBackListener();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
removeListeners(count: number): void {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Set listerner from native module for recorder.
|
|
63
|
+
* @returns {callBack((e: RecordBackType): void)}
|
|
64
|
+
*/
|
|
65
|
+
public addRecordBackListener(): void {
|
|
66
|
+
if (this.RecordBackListenerTimer) {
|
|
67
|
+
this.removeRecordBackListener();
|
|
68
|
+
}
|
|
69
|
+
this.AVRecorderInstance.onEvent(() => {
|
|
70
|
+
this.RecordBackListenerTimer = setInterval(async () => {
|
|
71
|
+
if (this.meteringEnabled) {
|
|
72
|
+
let maxAmplitude: number = 0;
|
|
73
|
+
let mediaRecorder: Recorder = this.AVRecorderInstance;
|
|
74
|
+
if (mediaRecorder != null) {
|
|
75
|
+
maxAmplitude = await mediaRecorder.getMaxAmplitude();
|
|
76
|
+
}
|
|
77
|
+
let dB: number = -160.0;
|
|
78
|
+
let maxAudioSize: number = 32767.0;
|
|
79
|
+
if (maxAmplitude > 0) {
|
|
80
|
+
dB = 20 * Math.log10(maxAmplitude / maxAudioSize);
|
|
81
|
+
dB = Math.floor(dB);
|
|
82
|
+
}
|
|
83
|
+
this.ctx.rnInstance.emitDeviceEvent(RecordBackName, {
|
|
84
|
+
isRecording: this.AVRecorderInstance.isRecording,
|
|
85
|
+
currentPosition: this.AVRecorderInstance.milliseconds,
|
|
86
|
+
currentMetering: dB,
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
this.ctx.rnInstance.emitDeviceEvent(RecordBackName, {
|
|
90
|
+
isRecording: this.AVRecorderInstance.isRecording,
|
|
91
|
+
currentPosition: this.AVRecorderInstance.milliseconds,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}, this.subscriptionDuration);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Remove listener for recorder.
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
102
|
+
public removeRecordBackListener(): void {
|
|
103
|
+
clearInterval(this.RecordBackListenerTimer);
|
|
104
|
+
this.RecordBackListenerTimer = null;
|
|
105
|
+
this.AVRecorderInstance.clearStartRecordCallback();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set listener from native module for player.
|
|
110
|
+
* @returns {callBack((e: PlayBackType): void)}
|
|
111
|
+
*/
|
|
112
|
+
public addPlayBackListener(): void {
|
|
113
|
+
if (this.PlayBackListenerTimer) {
|
|
114
|
+
this.removePlayBackListener();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.AVPlayerInstance.onEvent(EventTarget.timeUpdate, () => {
|
|
118
|
+
this.PlayBackListenerTimer = setInterval(() => {
|
|
119
|
+
this.ctx.rnInstance.emitDeviceEvent(playBackName, {
|
|
120
|
+
isMuted: this.AVPlayerInstance.isMuted,
|
|
121
|
+
isFinished: this.AVPlayerInstance.isFinished,
|
|
122
|
+
currentPosition: this.AVPlayerInstance.currentPosition,
|
|
123
|
+
duration: this.AVPlayerInstance.durationTime,
|
|
124
|
+
});
|
|
125
|
+
if (this.AVPlayerInstance.isFinished) {
|
|
126
|
+
this.stopPlayer();
|
|
127
|
+
}
|
|
128
|
+
}, this.subscriptionDuration);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* remove listener for player.
|
|
134
|
+
* @returns {void}
|
|
135
|
+
*/
|
|
136
|
+
public removePlayBackListener(): void {
|
|
137
|
+
clearInterval(this.PlayBackListenerTimer);
|
|
138
|
+
this.PlayBackListenerTimer = null;
|
|
139
|
+
this.AVPlayerInstance.mapClear();
|
|
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(recorderProcessValue.start);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!!!uri) {
|
|
157
|
+
return Promise.reject('empty uri');
|
|
158
|
+
}
|
|
159
|
+
this.meteringEnabled = meteringEnabled === true ? true : false;
|
|
160
|
+
const profile: media.AVRecorderProfile = this.getAudioSets(audioSets);
|
|
161
|
+
this.AVRecorderInstance.setAVProfile(profile, audioSets?.AudioSourceHarmony as number as media.AudioSourceType);
|
|
162
|
+
return this.AVRecorderInstance.startRecordingProcess(uri);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getAudioSets(audioSets?: AudioSet): media.AVRecorderProfile {
|
|
166
|
+
let audioCodec: media.CodecMimeType = media.CodecMimeType.AUDIO_AAC;
|
|
167
|
+
let fileFormat: media.ContainerFormatType =
|
|
168
|
+
audioSets?.AudioFileFormatHarmony as string as media.ContainerFormatType ||
|
|
169
|
+
media.ContainerFormatType.CFT_MPEG_4A; // 封装格式,当前只支持m4a, 12开始支持CFT_MP3, 20开始支持aac
|
|
170
|
+
if (audioSets?.AudioMimeHarmony) {
|
|
171
|
+
audioCodec = audioSets.AudioMimeHarmony as string as media.CodecMimeType;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (deviceInfo.sdkApiVersion < 20 && fileFormat === 'aac') {
|
|
175
|
+
fileFormat = media.ContainerFormatType.CFT_MPEG_4;
|
|
176
|
+
}
|
|
177
|
+
const avProfile: media.AVRecorderProfile = {
|
|
178
|
+
audioBitrate:
|
|
179
|
+
audioSets?.AudioSamplingRateHarmony ||
|
|
180
|
+
defaultBitrate, // 音频比特率
|
|
181
|
+
audioChannels:
|
|
182
|
+
audioSets?.AudioChannelsHarmony ||
|
|
183
|
+
defaultChannels, // 音频声道数
|
|
184
|
+
audioCodec: audioCodec, // 音频编码格式,当前只支持aac、vorbis、flac, 12开始支持AUDIO_MP3
|
|
185
|
+
audioSampleRate:
|
|
186
|
+
audioSets?.AudioSamplingRateHarmony ||
|
|
187
|
+
defaultSampleRate, // 音频采样率
|
|
188
|
+
fileFormat: fileFormat, // 音频文件封装格式
|
|
189
|
+
};
|
|
190
|
+
return avProfile;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Pause recording.
|
|
195
|
+
* @returns {Promise<string>}
|
|
196
|
+
*/
|
|
197
|
+
public async pauseRecorder(): Promise<string> {
|
|
198
|
+
if (this.AVRecorderInstance.recorderState === AVRecorderState.started) {
|
|
199
|
+
this.removeRecordBackListener();
|
|
200
|
+
return this.AVRecorderInstance.pauseRecordingProcess();
|
|
201
|
+
}
|
|
202
|
+
return Promise.reject(recorderProcessValue.stateError);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Resume recording.
|
|
207
|
+
* @returns {Promise<string>}
|
|
208
|
+
*/
|
|
209
|
+
public async resumeRecorder(): Promise<string> {
|
|
210
|
+
if (this.AVRecorderInstance.recorderState === AVRecorderState.paused) {
|
|
211
|
+
this.addRecordBackListener();
|
|
212
|
+
return this.AVRecorderInstance.resumeRecordingProcess();
|
|
213
|
+
}
|
|
214
|
+
return Promise.reject(recorderProcessValue.stateError);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* stop recording.
|
|
219
|
+
* @returns {Promise<string>}
|
|
220
|
+
*/
|
|
221
|
+
public async stopRecorder(): Promise<string> {
|
|
222
|
+
if (
|
|
223
|
+
[AVRecorderState.started, AVRecorderState.paused].includes(
|
|
224
|
+
this.AVRecorderInstance.recorderState,
|
|
225
|
+
)
|
|
226
|
+
) {
|
|
227
|
+
// 仅在started或者paused状态下调用stop为合理状态切换
|
|
228
|
+
this.removeRecordBackListener();
|
|
229
|
+
return this.AVRecorderInstance.stopRecordingProcess();
|
|
230
|
+
}
|
|
231
|
+
return Promise.reject(recorderProcessValue.stateError);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Start playing with param.
|
|
236
|
+
* @param {string} uri audio uri.
|
|
237
|
+
* @returns {Promise<string>}
|
|
238
|
+
*/
|
|
239
|
+
public async startPlayer(uri?: string, httpHeaders?: Record<string, string>): Promise<string> {
|
|
240
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.paused) {
|
|
241
|
+
return this.resumePlayer();
|
|
242
|
+
}
|
|
243
|
+
const url = await this.AVPlayerInstance.startPlayeringProcess(uri, httpHeaders);
|
|
244
|
+
!!url && this.addPlayBackListener();
|
|
245
|
+
return url;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Resume playing.
|
|
250
|
+
* @returns {Promise<string>}
|
|
251
|
+
*/
|
|
252
|
+
public async resumePlayer(): Promise<string> {
|
|
253
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.paused) {
|
|
254
|
+
this.addPlayBackListener();
|
|
255
|
+
return this.AVPlayerInstance.resumePlayeringProcess();
|
|
256
|
+
}
|
|
257
|
+
return Promise.reject(processValue.stateError);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Stop playing.
|
|
262
|
+
* @returns {Promise<string>}
|
|
263
|
+
*/
|
|
264
|
+
public async stopPlayer(): Promise<string> {
|
|
265
|
+
this.removePlayBackListener();
|
|
266
|
+
return this.AVPlayerInstance.stopPlayeringProcess();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Pause playing.
|
|
271
|
+
* @returns {Promise<string>}
|
|
272
|
+
*/
|
|
273
|
+
public async pausePlayer(): Promise<string> {
|
|
274
|
+
if (this.AVPlayerInstance.PlayerState === AVPlayerState.playing) {
|
|
275
|
+
this.removePlayBackListener();
|
|
276
|
+
return this.AVPlayerInstance.pausePlayeringProcess();
|
|
277
|
+
}
|
|
278
|
+
return Promise.reject(processValue.stateError);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Seek to.
|
|
283
|
+
* @param {number} time position seek to in millisecond.
|
|
284
|
+
* @returns {Promise<string>}
|
|
285
|
+
*/
|
|
286
|
+
public async seekToPlayer(time: number): Promise<string> {
|
|
287
|
+
if (!this.AVPlayerInstance.seekToPlayer) {
|
|
288
|
+
return Promise.reject(processValue.stateError);
|
|
289
|
+
}
|
|
290
|
+
return this.AVPlayerInstance.seekToPlayer(time);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Set volume.
|
|
295
|
+
* @param {number} setVolume set volume.
|
|
296
|
+
* @returns {Promise<string>}
|
|
297
|
+
*/
|
|
298
|
+
async setVolume(volume: number): Promise<string> {
|
|
299
|
+
if (!this.AVPlayerInstance.setVolume) {
|
|
300
|
+
return Promise.reject(processValue.stateError);
|
|
301
|
+
}
|
|
302
|
+
return this.AVPlayerInstance.setVolume(volume);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async setSubscriptionDuration(sec: number): Promise<string> {
|
|
306
|
+
const milliseconds = sec * 1000;
|
|
307
|
+
this.subscriptionDuration = milliseconds;
|
|
308
|
+
return sec.toString();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private isRecording(): boolean {
|
|
312
|
+
return [AVRecorderState.started, AVRecorderState.paused].includes(
|
|
313
|
+
this.AVRecorderInstance.recorderState,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|