@react-native-ohos/react-native-audio-recorder-player 3.6.14-rc.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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +14 -0
  4. package/RNAudioRecorderPlayer.podspec +21 -0
  5. package/harmony/audio_recorder_player/BuildProfile.ets +17 -0
  6. package/harmony/audio_recorder_player/LICENSE +21 -0
  7. package/harmony/audio_recorder_player/build-profile.json5 +28 -0
  8. package/harmony/audio_recorder_player/hvigorfile.ts +1 -0
  9. package/harmony/audio_recorder_player/index.ets +25 -0
  10. package/harmony/audio_recorder_player/oh-package-lock.json5 +18 -0
  11. package/harmony/audio_recorder_player/oh-package.json5 +20 -0
  12. package/harmony/audio_recorder_player/src/main/cpp/CMakeLists.txt +7 -0
  13. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerPackage.h +48 -0
  14. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.cpp +91 -0
  15. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.h +36 -0
  16. package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerPackage.ts +47 -0
  17. package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +315 -0
  18. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +464 -0
  19. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/types.ts +45 -0
  20. package/harmony/audio_recorder_player/src/main/ets/index.d.ts +209 -0
  21. package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +299 -0
  22. package/harmony/audio_recorder_player/src/main/ets/recorder/types.ts +61 -0
  23. package/harmony/audio_recorder_player/src/main/ets/utils/DateTimeUtils.ts +88 -0
  24. package/harmony/audio_recorder_player/src/main/ets/utils/Logger.ts +45 -0
  25. package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +105 -0
  26. package/harmony/audio_recorder_player/src/main/module.json5 +9 -0
  27. package/harmony/audio_recorder_player/src/main/resources/base/element/string.json +8 -0
  28. package/harmony/audio_recorder_player/src/main/resources/base/media/ic_public_error.svg +10 -0
  29. package/harmony/audio_recorder_player/src/main/resources/en_US/element/string.json +8 -0
  30. package/harmony/audio_recorder_player/src/main/resources/zh_CN/element/string.json +8 -0
  31. package/harmony/audio_recorder_player/ts.ts +27 -0
  32. package/harmony/audio_recorder_player.har +0 -0
  33. package/index.d.ts +226 -0
  34. package/index.ts +538 -0
  35. package/package.json +59 -0
  36. package/src/NativeAudioRecorderPlayerModule.ts +43 -0
@@ -0,0 +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
+ }
@@ -0,0 +1,61 @@
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
+
9
+ export const defaultBitrate: number = 48000;
10
+
11
+ export const defaultSampleRate: number = 48000;
12
+
13
+ export const defaultChannels: number = 2;
14
+
15
+ export const defaultTimeOut: number = 200;
16
+
17
+ export const TAG: string = 'Audio_Recorder';
18
+
19
+ export const RecordBackName: string = 'rn-recordback';
20
+
21
+ export const fdPath: string = 'fd://';
22
+
23
+ export enum PERMISSIONS {
24
+ MICROPHONE = 'ohos.permission.MICROPHONE',
25
+ WRITE_MEDIA = 'ohos.permission.WRITE_MEDIA',
26
+ READ_MEDIA = 'ohos.permission.READ_MEDIA',
27
+ }
28
+
29
+ export const avProfile: media.AVRecorderProfile = {
30
+ audioBitrate: defaultBitrate, // set audioBitrate according to device ability
31
+ audioChannels: defaultChannels, // set audioChannels, valid value 1-8
32
+ audioCodec: media.CodecMimeType.AUDIO_AAC, // set audioCodec, AUDIO_AAC is the only choice
33
+ audioSampleRate: defaultSampleRate, // set audioSampleRate according to device ability
34
+ fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // set fileFormat, for video is m4a
35
+ };
36
+
37
+ export const avConfig: media.AVRecorderConfig = {
38
+ audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
39
+ profile: avProfile,
40
+ url: fdPath,
41
+ };
42
+
43
+ export enum AVRecorderState {
44
+ idle = 'idle',
45
+ prepared = 'prepared',
46
+ started = 'started',
47
+ paused = 'paused',
48
+ stopped = 'stopped',
49
+ released = 'released',
50
+ error = 'error',
51
+ onStateChange = 'stateChange',
52
+ }
53
+
54
+ export enum processValue {
55
+ start = 'Already recording.',
56
+ pause = 'Already paused recording.',
57
+ resume = 'Currently recording.',
58
+ stop = 'Already stopped',
59
+ NoPermissions = 'No permissions of recorder',
60
+ stateError = 'current state is not allowed',
61
+ }
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ export default class DateTimeUtil {
17
+ getTime(): string {
18
+ const DATETIME = new Date();
19
+ return this.concatTime(
20
+ DATETIME.getHours(),
21
+ DATETIME.getMinutes(),
22
+ DATETIME.getSeconds(),
23
+ );
24
+ }
25
+
26
+ getDate(): string {
27
+ const DATETIME = new Date();
28
+ return this.concatDate(
29
+ DATETIME.getFullYear(),
30
+ DATETIME.getMonth() + 1,
31
+ DATETIME.getDate(),
32
+ );
33
+ }
34
+
35
+ fill(value: number): string {
36
+ return (value > 9 ? '' : '0') + value;
37
+ }
38
+
39
+ concatDate(year: number, month: number, date: number): string {
40
+ return `${year}${month}${date}`;
41
+ }
42
+
43
+ concatTime(hour: number, minute: number, second: number): string {
44
+ return `${this.fill(hour)}${this.fill(minute)}${this.fill(second)}`;
45
+ }
46
+ }
47
+
48
+ export function getShownTimer(ms: number): string {
49
+ let seconds: number = Math.round(ms / 1000);
50
+ let sec: number | string = seconds % 60;
51
+ let min: number | string = (seconds - sec) / 60;
52
+ if (sec < 10) {
53
+ sec = '0' + sec;
54
+ }
55
+ if (min < 10) {
56
+ min = '0' + min;
57
+ }
58
+ return min + ':' + sec;
59
+ }
60
+
61
+ export function dateTime(t: number): string {
62
+ let minute: number = Math.floor(t / 60) % 60;
63
+ let m = minute < 10 ? '0' + minute : minute;
64
+ let second: number = t % 60;
65
+ let s = second < 10 ? '0' + second : second;
66
+ return m + ':' + s;
67
+ }
68
+
69
+ export function getMMSSSS(milisecs: number): string {
70
+ const secs = Math.floor(milisecs / 1000);
71
+ const minutes = Math.floor(secs / 60);
72
+ const seconds = secs % 60;
73
+ const miliseconds = Math.floor((milisecs % 1000) / 10);
74
+ return `${formatString(minutes)}:${formatString(
75
+ seconds,
76
+ )}:${formatString(miliseconds)}`;
77
+ }
78
+
79
+ export function getMMSS(milisecs: number): string {
80
+ const secs = Math.floor(milisecs / 1000);
81
+ const minutes = Math.floor(secs / 60);
82
+ const seconds = secs % 60;
83
+ return `${formatString(minutes)}:${formatString(seconds)}`;
84
+ }
85
+
86
+ function formatString(num: number): string {
87
+ return `0${num}`.slice(-2);
88
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import hilog from '@ohos.hilog';
17
+
18
+ class Logger {
19
+ private domain: number;
20
+ private prefix: string;
21
+ private format: string = '%{public}s, %{public}s';
22
+
23
+ constructor(prefix: string) {
24
+ this.prefix = prefix;
25
+ this.domain = 0xff00;
26
+ }
27
+
28
+ debug(...args: string[]): void {
29
+ hilog.debug(this.domain, this.prefix, this.format, args);
30
+ }
31
+
32
+ info(...args: string[]): void {
33
+ hilog.info(this.domain, this.prefix, this.format, args);
34
+ }
35
+
36
+ warn(...args: string[]): void {
37
+ hilog.warn(this.domain, this.prefix, this.format, args);
38
+ }
39
+
40
+ error(...args: string[]): void {
41
+ hilog.error(this.domain, this.prefix, this.format, args);
42
+ }
43
+ }
44
+
45
+ export default new Logger('AVRecorderSample');
@@ -0,0 +1,105 @@
1
+ /*
2
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import DateTimeUtil from './DateTimeUtils';
17
+ import Logger from './Logger';
18
+ import fs from '@ohos.file.fs';
19
+ import { common } from '@kit.AbilityKit';
20
+ import audio from '@ohos.multimedia.audio';
21
+ import { uri } from '@kit.ArkTS';
22
+ import { media } from '@kit.MediaKit';
23
+
24
+ export default class SaveCameraAsset {
25
+ public file: fs.File;
26
+ private tag: string;
27
+ private lastSaveTime: string = '';
28
+ private saveIndex: number = 0;
29
+ private audioManager: audio.AudioManager = audio.getAudioManager();
30
+ private audioVolumeManager: audio.AudioVolumeManager =
31
+ this.audioManager.getVolumeManager();
32
+ private audioVolumeGroupManager =
33
+ this.audioVolumeManager.getVolumeGroupManagerSync(
34
+ audio.DEFAULT_VOLUME_GROUP_ID,
35
+ );
36
+ private fileName: string;
37
+ private context: common.UIAbilityContext;
38
+
39
+ constructor(tag: string, context: common.UIAbilityContext) {
40
+ this.tag = tag;
41
+ this.context = context;
42
+ }
43
+
44
+ public async createAudioFd(url?: string, fileFormat?: media.ContainerFormatType): Promise<number> {
45
+ Logger.info(this.tag, 'get Recorder File Fd');
46
+ const context = this.context as common.UIAbilityContext;
47
+ let path = '';
48
+ if (uri) {
49
+ path = `${context.filesDir}/${url}`;
50
+ this.fileName = url;
51
+ if (url === 'DEFAULT') {
52
+ path = `${context.filesDir}/${'sound.'}${fileFormat ? fileFormat : media.ContainerFormatType.CFT_MPEG_4A}`;
53
+ this.fileName = `${'sound.'}${fileFormat ? fileFormat : media.ContainerFormatType.CFT_MPEG_4A}`;
54
+ }
55
+ } else {
56
+ const mDateTimeUtil = new DateTimeUtil();
57
+ const displayName = this.checkName(
58
+ `REC_${mDateTimeUtil.getDate()}_${mDateTimeUtil.getTime()}.m4a`,
59
+ );
60
+ path = `${context.filesDir}/${displayName}`;
61
+ this.fileName = displayName;
62
+ }
63
+
64
+ this.file = this.createOrOpen(path);
65
+ return this.file?.fd ?? 0;
66
+ }
67
+
68
+ public getFilePath() {
69
+ return this.file.path;
70
+ }
71
+
72
+ public getFileName() {
73
+ return this.fileName;
74
+ }
75
+
76
+ public mediaIsMute(): boolean {
77
+ return this.audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA);
78
+ }
79
+
80
+ public closeFile() {
81
+ fs.closeSync(this.file);
82
+ }
83
+
84
+ private createOrOpen(path: string): fs.File {
85
+ const isExist = fs.accessSync(path);
86
+ let file: fs.File;
87
+ if (isExist) {
88
+ file = fs.openSync(path, fs.OpenMode.READ_WRITE);
89
+ } else {
90
+ file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
91
+ }
92
+ return file;
93
+ }
94
+
95
+ private checkName(name: string): string {
96
+ if (this.lastSaveTime == name) {
97
+ this.saveIndex += 1;
98
+ return `${name}_${this.saveIndex}`;
99
+ }
100
+ this.lastSaveTime = name;
101
+ this.saveIndex = 0;
102
+ Logger.info(this.tag, 'get Recorder File name is: ' + name);
103
+ return name;
104
+ }
105
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "module": {
3
+ "name": "audio_recorder_player",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ "default"
7
+ ],
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" viewBox="0 0 24 24" version="1.1">
3
+ <!-- Generator: Sketch 63.1 (92452) - https://sketch.com -->
4
+ <title>Public/ic_public_error</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <g id="_Public/ic_public_error" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
7
+ <circle id="_colorError" fill="#E84026" cx="12" cy="12" r="11"/>
8
+ <path d="M12,15.5 C12.6903125,15.5 13.25,16.0596875 13.25,16.75 C13.25,17.4403125 12.6903125,18 12,18 C11.3096875,18 10.75,17.4403125 10.75,16.75 C10.75,16.0596875 11.3096875,15.5 12,15.5 Z M12,6 C12.6414582,6 13.1614628,6.5200046 13.1614628,7.16146279 C13.1614628,7.18988207 13.1604197,7.21829177 13.1583357,7.24663453 L12.6708322,13.8766827 C12.6449936,14.2280877 12.3523536,14.5 12,14.5 C11.6476464,14.5 11.3550064,14.2280877 11.3291678,13.8766827 L10.8416643,7.24663453 C10.7946252,6.60690339 11.2750971,6.05016615 11.9148283,6.00312709 C11.943171,6.00104307 11.9715807,6 12,6 Z" id="_形状结合" fill="#FFFFFF"/>
9
+ </g>
10
+ </svg>
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,27 @@
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
+ export * from './src/main/ets/RNAudioRecorderPlayerPackage';
26
+
27
+ export * from './src/main/ets/RNAudioRecorderPlayerTurboModule';