@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.
Files changed (33) hide show
  1. package/LICENSE +20 -20
  2. package/README.OpenSource +10 -10
  3. package/README.md +822 -753
  4. package/harmony/audio_recorder_player/BuildProfile.ets +16 -16
  5. package/harmony/audio_recorder_player/LICENSE +21 -21
  6. package/harmony/audio_recorder_player/build-profile.json5 +28 -28
  7. package/harmony/audio_recorder_player/index.ets +27 -25
  8. package/harmony/audio_recorder_player/oh-package-lock.json5 +18 -0
  9. package/harmony/audio_recorder_player/oh-package.json5 +20 -20
  10. package/harmony/audio_recorder_player/src/main/cpp/CMakeLists.txt +7 -7
  11. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerPackage.h +48 -48
  12. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.cpp +90 -90
  13. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.h +35 -35
  14. package/harmony/audio_recorder_player/src/main/ets/{RNAudioRecorderPlayerPackage.ts → RNAudioRecorderPlayerPackage.ets} +48 -47
  15. package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +324 -323
  16. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +464 -464
  17. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/types.ts +45 -45
  18. package/harmony/audio_recorder_player/src/main/ets/index.ts +209 -209
  19. package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +299 -299
  20. package/harmony/audio_recorder_player/src/main/ets/recorder/types.ts +61 -61
  21. package/harmony/audio_recorder_player/src/main/ets/utils/DateTimeUtils.ts +88 -88
  22. package/harmony/audio_recorder_player/src/main/ets/utils/Logger.ts +45 -45
  23. package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +105 -105
  24. package/harmony/audio_recorder_player/src/main/module.json5 +9 -9
  25. package/harmony/audio_recorder_player/src/main/resources/base/element/string.json +8 -8
  26. package/harmony/audio_recorder_player/src/main/resources/base/media/ic_public_error.svg +9 -9
  27. package/harmony/audio_recorder_player/src/main/resources/en_US/element/string.json +8 -8
  28. package/harmony/audio_recorder_player/src/main/resources/zh_CN/element/string.json +8 -8
  29. package/harmony/audio_recorder_player/{ts.ts → ts.ets} +26 -26
  30. package/harmony/audio_recorder_player.har +0 -0
  31. package/index.ts +539 -539
  32. package/package.json +71 -60
  33. package/src/NativeAudioRecorderPlayerModule.ts +42 -42
@@ -1,299 +1,299 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import media from '@ohos.multimedia.media';
8
- import { BusinessError } from '@kit.BasicServicesKit';
9
- import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
10
- import { common } from '@kit.AbilityKit';
11
- import { avConfig, avProfile, AVRecorderState, defaultTimeOut, fdPath, PERMISSIONS, processValue, TAG, } from './types';
12
- import Logger from '../utils/Logger';
13
- import SaveAudioAsset from '../utils/SaveAudioAsset';
14
-
15
- export default class Recorder {
16
- public isRecording: boolean = false;
17
- public milliseconds: number = 0;
18
- public recorderState: AVRecorderState;
19
- private audioRecorder: media.AVRecorder;
20
- private fdPath: string;
21
- private timer;
22
- private mSaveAudioAsset: SaveAudioAsset;
23
- private permissions: Array<Permissions> = [
24
- PERMISSIONS.MICROPHONE,
25
- PERMISSIONS.READ_MEDIA,
26
- PERMISSIONS.WRITE_MEDIA,
27
- ];
28
- private atManager: abilityAccessCtrl.AtManager =
29
- abilityAccessCtrl.createAtManager();
30
- private mFileAssetId: number;
31
- private avProfile: media.AVRecorderProfile;
32
- private avConfig: media.AVRecorderConfig;
33
- private startRecordCallback: () => void;
34
- private context: common.UIAbilityContext;
35
-
36
- constructor(context: common.UIAbilityContext) {
37
- this.context = context;
38
- this.mSaveAudioAsset = new SaveAudioAsset(TAG, context);
39
- }
40
-
41
- public setAVProfile(newValue: media.AVRecorderProfile, audioSource?: media.AudioSourceType) {
42
- this.avProfile = {
43
- ...avProfile,
44
- ...newValue,
45
- };
46
- if (audioSource) {
47
- avConfig.audioSourceType = audioSource;
48
- }
49
- this.avConfig = {
50
- ...avConfig,
51
- profile: this.avProfile,
52
- };
53
- }
54
-
55
- public onEvent(callback: () => void) {
56
- this.startRecordCallback = callback;
57
- }
58
-
59
- // start button process
60
- async startRecordingProcess(url?: string): Promise<string> {
61
- Logger.debug(TAG, 'startRecording called', this.recorderState);
62
- if (this.isRecording) {
63
- Logger.debug(TAG, 'audioRecorder exist,release it');
64
- return processValue.stateError;
65
- }
66
- const isPermissions: boolean = await this.requestPermissions();
67
- if (isPermissions) {
68
- await this.getFileFd(url);
69
- await this.createAudioRecorder();
70
- await this.prepareAudioRecorder();
71
- Logger.debug(TAG, 'startRecording done');
72
- return this.mSaveAudioAsset.getFilePath();
73
- }
74
- return processValue.NoPermissions;
75
- }
76
-
77
- // pause button process
78
- async pauseRecordingProcess(): Promise<string | undefined> {
79
- Logger.debug(TAG, 'pauseRecording called');
80
- if (this.recorderState === AVRecorderState.started) {
81
- Logger.debug(TAG, 'current state is started, to pause');
82
- return this.audioRecorder.pause().then(() => processValue.pause);
83
- }
84
- Logger.debug(TAG, 'pauseRecording done');
85
- return processValue.stateError;
86
- }
87
-
88
- // resume button process
89
- async resumeRecordingProcess(): Promise<string | undefined> {
90
- Logger.debug(TAG, 'resumeRecording called');
91
- if (this.recorderState === AVRecorderState.paused) {
92
- Logger.debug(TAG, 'current state is paused, to resume');
93
- this.isRecording = true;
94
- return this.audioRecorder.resume().then(() => processValue.resume);
95
- }
96
- Logger.debug(TAG, 'resumeRecording done');
97
- return processValue.stateError;
98
- }
99
-
100
- // stop button process
101
- async stopRecordingProcess(): Promise<string | undefined> {
102
- Logger.debug(TAG, 'stopRecording called');
103
- clearInterval(this.timer);
104
- this.isRecording = false;
105
- this.milliseconds = 0;
106
- await this.audioRecorder.stop();
107
- Logger.debug(TAG, 'stopRecording stop');
108
- await this.closeFd();
109
- Logger.debug(TAG, 'stopRecording closeFd');
110
- await this.resetAudioRecording();
111
- Logger.debug(TAG, 'stopRecording reset');
112
- await this.releaseAudioRecorder();
113
- Logger.debug(TAG, 'stopRecording release');
114
- return this.getFilePath();
115
- }
116
-
117
- private async catchCallback(error: BusinessError): Promise<void> {
118
- Logger.debug(
119
- TAG,
120
- `catchCallback code:${error.code} message:${error.message}`,
121
- );
122
- }
123
-
124
- private async requestPermissions(): Promise<boolean> {
125
- return await new Promise((resolve: Function) => {
126
- try {
127
- const context = this.context as common.UIAbilityContext;
128
- this.atManager
129
- .requestPermissionsFromUser(context, this.permissions)
130
- .then(async () => {
131
- resolve(true);
132
- })
133
- .catch(() => {
134
- resolve(false);
135
- });
136
- } catch (err) {
137
- resolve(false);
138
- }
139
- });
140
- }
141
-
142
- // show recording time
143
- private getRecordTime(): void {
144
- this.timer = setInterval(() => {
145
- this.milliseconds += defaultTimeOut;
146
- }, defaultTimeOut);
147
- }
148
-
149
- // create file fd
150
- private async getFileFd(url?: string): Promise<void> {
151
- Logger.debug(TAG, 'getFileFd called');
152
- return new Promise(async (resolve, reject) => {
153
- if (url && url.startsWith(fdPath)) {
154
- this.avConfig.url = url;
155
- Logger.debug(TAG, 'url is :', url);
156
- resolve();
157
- return;
158
- }
159
- this.mFileAssetId = await this.mSaveAudioAsset.createAudioFd(url,
160
- this.avConfig?.profile?.fileFormat || media.ContainerFormatType.CFT_MPEG_4A);
161
- if (!this.mFileAssetId) {
162
- reject();
163
- return;
164
- }
165
- this.fdPath = fdPath + this.mFileAssetId.toString();
166
- this.avConfig.url = this.fdPath;
167
- Logger.debug(TAG, 'fdPath is: ' + this.fdPath);
168
- Logger.debug(TAG, 'getFileFd done');
169
- resolve();
170
- });
171
- }
172
-
173
- private async createAudioRecorder(): Promise<void> {
174
- await media
175
- .createAVRecorder()
176
- .then((recorder) => {
177
- Logger.debug(TAG, 'case createAVRecorder called');
178
- if (!!recorder) {
179
- this.audioRecorder = recorder;
180
- this.setCallback();
181
- } else {
182
- Logger.debug(TAG, 'case create avRecorder failed!!!');
183
- }
184
- })
185
- .catch(this.catchCallback);
186
- }
187
-
188
- // set callback on
189
- private setCallback(): void {
190
- Logger.debug(TAG, 'case callback');
191
- this.audioRecorder!.on(
192
- AVRecorderState.onStateChange,
193
- (state: media.AVRecorderState) => {
194
- Logger.debug(TAG, 'case state has changed, new state is' + state);
195
- switch (state) {
196
- case AVRecorderState.idle: {
197
- this.recorderState = AVRecorderState.idle;
198
- break;
199
- }
200
- case AVRecorderState.prepared: {
201
- this.recorderState = AVRecorderState.prepared;
202
- break;
203
- }
204
- case AVRecorderState.started: {
205
- this.recorderState = AVRecorderState.started;
206
- if (this.startRecordCallback) {
207
- this.startRecordCallback();
208
- }
209
- this.getRecordTime();
210
- this.isRecording = true;
211
- break;
212
- }
213
- case AVRecorderState.paused: {
214
- this.recorderState = AVRecorderState.paused;
215
- this.isRecording = false;
216
- clearInterval(this.timer);
217
- break;
218
- }
219
- case AVRecorderState.stopped: {
220
- this.recorderState = AVRecorderState.stopped;
221
- this.isRecording = false;
222
- break;
223
- }
224
- case AVRecorderState.released: {
225
- this.recorderState = AVRecorderState.released;
226
- this.isRecording = false;
227
- break;
228
- }
229
- default:
230
- Logger.debug(TAG, 'case start is unknown');
231
- break;
232
- }
233
- },
234
- );
235
- this.audioRecorder!.on(AVRecorderState.error, (err) => {
236
- this.stopRecordingProcess();
237
- Logger.debug(
238
- TAG,
239
- 'case avRecorder.on(error) called, errMessage is ' + err.code,
240
- );
241
- });
242
- }
243
-
244
- private async prepareAudioRecorder(): Promise<void> {
245
- Logger.debug(TAG, 'case prepareAudioRecorder in');
246
- await this.audioRecorder!.prepare(this.avConfig)
247
- .then(() => {
248
- this.audioRecorder!.start();
249
- Logger.debug(TAG, 'case prepare AVRecorder called');
250
- }, this.catchCallback)
251
- .catch(this.catchCallback);
252
- Logger.debug(TAG, 'case prepareAudioRecorder out');
253
- }
254
-
255
- private async resetAudioRecording(): Promise<void> {
256
- await this.audioRecorder!.reset()
257
- .then(() => {
258
- Logger.debug(TAG, 'case resetAudioRecording called');
259
- }, this.catchCallback)
260
- .catch(this.catchCallback);
261
- }
262
-
263
- private async releaseAudioRecorder(): Promise<void> {
264
- if (this.audioRecorder) {
265
- await this.audioRecorder.off(AVRecorderState.onStateChange);
266
- await this.audioRecorder.off(AVRecorderState.error);
267
- this.audioRecorder
268
- .release()
269
- .then(() => {
270
- this.audioRecorder = undefined;
271
- Logger.debug(TAG, 'case releaseAudioRecorder called');
272
- }, this.catchCallback)
273
- .catch(this.catchCallback);
274
- }
275
- }
276
-
277
- // close file fd
278
- private async closeFd(): Promise<void> {
279
- Logger.debug(TAG, 'case closeFd called');
280
- if (this.fdPath) {
281
- this.mSaveAudioAsset.closeFile();
282
- this.mFileAssetId = -1;
283
- this.fdPath = '';
284
- Logger.debug(TAG, 'case closeFd done');
285
- }
286
- }
287
-
288
- private getFilePath(): string {
289
- const context = this.context as common.UIAbilityContext;
290
- return `${context.filesDir}/${this.mSaveAudioAsset.getFileName()}`;
291
- }
292
-
293
- public getMaxAmplitude(): Promise<number> {
294
- if (!this.audioRecorder) {
295
- return new Promise((resolve) => resolve(0));
296
- }
297
- return this.audioRecorder.getAudioCapturerMaxAmplitude();
298
- }
299
- }
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import media from '@ohos.multimedia.media';
8
+ import { BusinessError } from '@kit.BasicServicesKit';
9
+ import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
10
+ import { common } from '@kit.AbilityKit';
11
+ import { avConfig, avProfile, AVRecorderState, defaultTimeOut, fdPath, PERMISSIONS, processValue, TAG, } from './types';
12
+ import Logger from '../utils/Logger';
13
+ import SaveAudioAsset from '../utils/SaveAudioAsset';
14
+
15
+ export default class Recorder {
16
+ public isRecording: boolean = false;
17
+ public milliseconds: number = 0;
18
+ public recorderState: AVRecorderState;
19
+ private audioRecorder: media.AVRecorder;
20
+ private fdPath: string;
21
+ private timer;
22
+ private mSaveAudioAsset: SaveAudioAsset;
23
+ private permissions: Array<Permissions> = [
24
+ PERMISSIONS.MICROPHONE,
25
+ PERMISSIONS.READ_MEDIA,
26
+ PERMISSIONS.WRITE_MEDIA,
27
+ ];
28
+ private atManager: abilityAccessCtrl.AtManager =
29
+ abilityAccessCtrl.createAtManager();
30
+ private mFileAssetId: number;
31
+ private avProfile: media.AVRecorderProfile;
32
+ private avConfig: media.AVRecorderConfig;
33
+ private startRecordCallback: () => void;
34
+ private context: common.UIAbilityContext;
35
+
36
+ constructor(context: common.UIAbilityContext) {
37
+ this.context = context;
38
+ this.mSaveAudioAsset = new SaveAudioAsset(TAG, context);
39
+ }
40
+
41
+ public setAVProfile(newValue: media.AVRecorderProfile, audioSource?: media.AudioSourceType) {
42
+ this.avProfile = {
43
+ ...avProfile,
44
+ ...newValue,
45
+ };
46
+ if (audioSource) {
47
+ avConfig.audioSourceType = audioSource;
48
+ }
49
+ this.avConfig = {
50
+ ...avConfig,
51
+ profile: this.avProfile,
52
+ };
53
+ }
54
+
55
+ public onEvent(callback: () => void) {
56
+ this.startRecordCallback = callback;
57
+ }
58
+
59
+ // start button process
60
+ async startRecordingProcess(url?: string): Promise<string> {
61
+ Logger.debug(TAG, 'startRecording called', this.recorderState);
62
+ if (this.isRecording) {
63
+ Logger.debug(TAG, 'audioRecorder exist,release it');
64
+ return processValue.stateError;
65
+ }
66
+ const isPermissions: boolean = await this.requestPermissions();
67
+ if (isPermissions) {
68
+ await this.getFileFd(url);
69
+ await this.createAudioRecorder();
70
+ await this.prepareAudioRecorder();
71
+ Logger.debug(TAG, 'startRecording done');
72
+ return this.mSaveAudioAsset.getFilePath();
73
+ }
74
+ return processValue.NoPermissions;
75
+ }
76
+
77
+ // pause button process
78
+ async pauseRecordingProcess(): Promise<string | undefined> {
79
+ Logger.debug(TAG, 'pauseRecording called');
80
+ if (this.recorderState === AVRecorderState.started) {
81
+ Logger.debug(TAG, 'current state is started, to pause');
82
+ return this.audioRecorder.pause().then(() => processValue.pause);
83
+ }
84
+ Logger.debug(TAG, 'pauseRecording done');
85
+ return processValue.stateError;
86
+ }
87
+
88
+ // resume button process
89
+ async resumeRecordingProcess(): Promise<string | undefined> {
90
+ Logger.debug(TAG, 'resumeRecording called');
91
+ if (this.recorderState === AVRecorderState.paused) {
92
+ Logger.debug(TAG, 'current state is paused, to resume');
93
+ this.isRecording = true;
94
+ return this.audioRecorder.resume().then(() => processValue.resume);
95
+ }
96
+ Logger.debug(TAG, 'resumeRecording done');
97
+ return processValue.stateError;
98
+ }
99
+
100
+ // stop button process
101
+ async stopRecordingProcess(): Promise<string | undefined> {
102
+ Logger.debug(TAG, 'stopRecording called');
103
+ clearInterval(this.timer);
104
+ this.isRecording = false;
105
+ this.milliseconds = 0;
106
+ await this.audioRecorder.stop();
107
+ Logger.debug(TAG, 'stopRecording stop');
108
+ await this.closeFd();
109
+ Logger.debug(TAG, 'stopRecording closeFd');
110
+ await this.resetAudioRecording();
111
+ Logger.debug(TAG, 'stopRecording reset');
112
+ await this.releaseAudioRecorder();
113
+ Logger.debug(TAG, 'stopRecording release');
114
+ return this.getFilePath();
115
+ }
116
+
117
+ private async catchCallback(error: BusinessError): Promise<void> {
118
+ Logger.debug(
119
+ TAG,
120
+ `catchCallback code:${error.code} message:${error.message}`,
121
+ );
122
+ }
123
+
124
+ private async requestPermissions(): Promise<boolean> {
125
+ return await new Promise((resolve: Function) => {
126
+ try {
127
+ const context = this.context as common.UIAbilityContext;
128
+ this.atManager
129
+ .requestPermissionsFromUser(context, this.permissions)
130
+ .then(async () => {
131
+ resolve(true);
132
+ })
133
+ .catch(() => {
134
+ resolve(false);
135
+ });
136
+ } catch (err) {
137
+ resolve(false);
138
+ }
139
+ });
140
+ }
141
+
142
+ // show recording time
143
+ private getRecordTime(): void {
144
+ this.timer = setInterval(() => {
145
+ this.milliseconds += defaultTimeOut;
146
+ }, defaultTimeOut);
147
+ }
148
+
149
+ // create file fd
150
+ private async getFileFd(url?: string): Promise<void> {
151
+ Logger.debug(TAG, 'getFileFd called');
152
+ return new Promise(async (resolve, reject) => {
153
+ if (url && url.startsWith(fdPath)) {
154
+ this.avConfig.url = url;
155
+ Logger.debug(TAG, 'url is :', url);
156
+ resolve();
157
+ return;
158
+ }
159
+ this.mFileAssetId = await this.mSaveAudioAsset.createAudioFd(url,
160
+ this.avConfig?.profile?.fileFormat || media.ContainerFormatType.CFT_MPEG_4A);
161
+ if (!this.mFileAssetId) {
162
+ reject();
163
+ return;
164
+ }
165
+ this.fdPath = fdPath + this.mFileAssetId.toString();
166
+ this.avConfig.url = this.fdPath;
167
+ Logger.debug(TAG, 'fdPath is: ' + this.fdPath);
168
+ Logger.debug(TAG, 'getFileFd done');
169
+ resolve();
170
+ });
171
+ }
172
+
173
+ private async createAudioRecorder(): Promise<void> {
174
+ await media
175
+ .createAVRecorder()
176
+ .then((recorder) => {
177
+ Logger.debug(TAG, 'case createAVRecorder called');
178
+ if (!!recorder) {
179
+ this.audioRecorder = recorder;
180
+ this.setCallback();
181
+ } else {
182
+ Logger.debug(TAG, 'case create avRecorder failed!!!');
183
+ }
184
+ })
185
+ .catch(this.catchCallback);
186
+ }
187
+
188
+ // set callback on
189
+ private setCallback(): void {
190
+ Logger.debug(TAG, 'case callback');
191
+ this.audioRecorder!.on(
192
+ AVRecorderState.onStateChange,
193
+ (state: media.AVRecorderState) => {
194
+ Logger.debug(TAG, 'case state has changed, new state is' + state);
195
+ switch (state) {
196
+ case AVRecorderState.idle: {
197
+ this.recorderState = AVRecorderState.idle;
198
+ break;
199
+ }
200
+ case AVRecorderState.prepared: {
201
+ this.recorderState = AVRecorderState.prepared;
202
+ break;
203
+ }
204
+ case AVRecorderState.started: {
205
+ this.recorderState = AVRecorderState.started;
206
+ if (this.startRecordCallback) {
207
+ this.startRecordCallback();
208
+ }
209
+ this.getRecordTime();
210
+ this.isRecording = true;
211
+ break;
212
+ }
213
+ case AVRecorderState.paused: {
214
+ this.recorderState = AVRecorderState.paused;
215
+ this.isRecording = false;
216
+ clearInterval(this.timer);
217
+ break;
218
+ }
219
+ case AVRecorderState.stopped: {
220
+ this.recorderState = AVRecorderState.stopped;
221
+ this.isRecording = false;
222
+ break;
223
+ }
224
+ case AVRecorderState.released: {
225
+ this.recorderState = AVRecorderState.released;
226
+ this.isRecording = false;
227
+ break;
228
+ }
229
+ default:
230
+ Logger.debug(TAG, 'case start is unknown');
231
+ break;
232
+ }
233
+ },
234
+ );
235
+ this.audioRecorder!.on(AVRecorderState.error, (err) => {
236
+ this.stopRecordingProcess();
237
+ Logger.debug(
238
+ TAG,
239
+ 'case avRecorder.on(error) called, errMessage is ' + err.code,
240
+ );
241
+ });
242
+ }
243
+
244
+ private async prepareAudioRecorder(): Promise<void> {
245
+ Logger.debug(TAG, 'case prepareAudioRecorder in');
246
+ await this.audioRecorder!.prepare(this.avConfig)
247
+ .then(() => {
248
+ this.audioRecorder!.start();
249
+ Logger.debug(TAG, 'case prepare AVRecorder called');
250
+ }, this.catchCallback)
251
+ .catch(this.catchCallback);
252
+ Logger.debug(TAG, 'case prepareAudioRecorder out');
253
+ }
254
+
255
+ private async resetAudioRecording(): Promise<void> {
256
+ await this.audioRecorder!.reset()
257
+ .then(() => {
258
+ Logger.debug(TAG, 'case resetAudioRecording called');
259
+ }, this.catchCallback)
260
+ .catch(this.catchCallback);
261
+ }
262
+
263
+ private async releaseAudioRecorder(): Promise<void> {
264
+ if (this.audioRecorder) {
265
+ await this.audioRecorder.off(AVRecorderState.onStateChange);
266
+ await this.audioRecorder.off(AVRecorderState.error);
267
+ this.audioRecorder
268
+ .release()
269
+ .then(() => {
270
+ this.audioRecorder = undefined;
271
+ Logger.debug(TAG, 'case releaseAudioRecorder called');
272
+ }, this.catchCallback)
273
+ .catch(this.catchCallback);
274
+ }
275
+ }
276
+
277
+ // close file fd
278
+ private async closeFd(): Promise<void> {
279
+ Logger.debug(TAG, 'case closeFd called');
280
+ if (this.fdPath) {
281
+ this.mSaveAudioAsset.closeFile();
282
+ this.mFileAssetId = -1;
283
+ this.fdPath = '';
284
+ Logger.debug(TAG, 'case closeFd done');
285
+ }
286
+ }
287
+
288
+ private getFilePath(): string {
289
+ const context = this.context as common.UIAbilityContext;
290
+ return `${context.filesDir}/${this.mSaveAudioAsset.getFileName()}`;
291
+ }
292
+
293
+ public getMaxAmplitude(): Promise<number> {
294
+ if (!this.audioRecorder) {
295
+ return new Promise((resolve) => resolve(0));
296
+ }
297
+ return this.audioRecorder.getAudioCapturerMaxAmplitude();
298
+ }
299
+ }