@react-native-ohos/react-native-audio-recorder-player 3.6.11-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 (35) 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/LICENSE +21 -0
  6. package/harmony/audio_recorder_player/ResourceTable.txt +2 -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 +26 -0
  10. package/harmony/audio_recorder_player/oh-package.json5 +20 -0
  11. package/harmony/audio_recorder_player/src/main/cpp/CMakeLists.txt +7 -0
  12. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerPackage.h +53 -0
  13. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.cpp +93 -0
  14. package/harmony/audio_recorder_player/src/main/cpp/RNAudioRecorderPlayerTurboModule.h +38 -0
  15. package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerPackage.ets +48 -0
  16. package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +303 -0
  17. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +414 -0
  18. package/harmony/audio_recorder_player/src/main/ets/audioPlayer/types.ts +43 -0
  19. package/harmony/audio_recorder_player/src/main/ets/index.d.ts +209 -0
  20. package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +299 -0
  21. package/harmony/audio_recorder_player/src/main/ets/recorder/types.ts +61 -0
  22. package/harmony/audio_recorder_player/src/main/ets/utils/DateTimeUtils.ts +88 -0
  23. package/harmony/audio_recorder_player/src/main/ets/utils/Logger.ts +45 -0
  24. package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +105 -0
  25. package/harmony/audio_recorder_player/src/main/module.json5 +9 -0
  26. package/harmony/audio_recorder_player/src/main/resources/base/element/string.json +8 -0
  27. package/harmony/audio_recorder_player/src/main/resources/base/media/ic_public_error.svg +10 -0
  28. package/harmony/audio_recorder_player/src/main/resources/en_US/element/string.json +8 -0
  29. package/harmony/audio_recorder_player/src/main/resources/zh_CN/element/string.json +8 -0
  30. package/harmony/audio_recorder_player/ts.ets +27 -0
  31. package/harmony/audio_recorder_player.har +0 -0
  32. package/index.d.ts +226 -0
  33. package/index.ts +524 -0
  34. package/package.json +69 -0
  35. package/src/NativeAudioRecorderPlayerModule.ts +42 -0
@@ -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';
package/index.d.ts ADDED
@@ -0,0 +1,226 @@
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 enum AudioSourceHarmonyType {
26
+ DEFAULT = 0,
27
+ MIC,
28
+ VOICE_RECOGNITION,
29
+ VOICE_COMMUNICATION = 7,
30
+ VOICE_MESSAGE = 10,
31
+ CAMCORDER = 12,
32
+ }
33
+
34
+ export enum AudioFormatHarmonyType {
35
+ MPEG_4 = 'mp4',
36
+ MPEG_4A = 'm4a',
37
+ MP3 = 'mp3',
38
+ WAV = 'wav'
39
+ }
40
+
41
+ export enum AudioMimeHarmonyType {
42
+ AUDIO_AAC = 'audio/mp4a-latm', // 表示音频/mp4a-latm类型。
43
+
44
+ AUDIO_VORBIS = 'audio/vorbis', // 表示音频/vorbis类型。
45
+ AUDIO_FLAC = 'audio/flac', // 表示音频/flac类型。
46
+ AUDIO_MP3 = 'audio/mpeg', // 表示音频/mpeg类型。
47
+ AUDIO_G711MU = 'audio/g711mu', // 表示音频/G711-mulaw类型。
48
+ }
49
+
50
+ export enum AudioSourceAndroidType {
51
+ DEFAULT = 0,
52
+ MIC,
53
+ }
54
+
55
+ export enum OutputFormatAndroidType {
56
+ DEFAULT = 0,
57
+ THREE_GPP,
58
+ MPEG_4,
59
+ AMR_NB,
60
+ AMR_WB,
61
+ AAC_ADIF,
62
+ AAC_ADTS,
63
+ OUTPUT_FORMAT_RTP_AVP,
64
+ MPEG_2_TS,
65
+ WEBM,
66
+ UNUSED,
67
+ OGG,
68
+ }
69
+
70
+ export enum AudioEncoderAndroidType {
71
+ DEFAULT = 0,
72
+ AMR_NB,
73
+ AMR_WB,
74
+ AAC,
75
+ HE_AAC,
76
+ AAC_ELD,
77
+ VORBIS,
78
+ OPUS,
79
+ }
80
+
81
+ export enum AVEncodingOption {
82
+ lpcm = 'lpcm',
83
+ ima4 = 'ima4',
84
+ aac = 'aac',
85
+ MAC3 = 'MAC3',
86
+ MAC6 = 'MAC6',
87
+ ulaw = 'ulaw',
88
+ alaw = 'alaw',
89
+ mp1 = 'mp1',
90
+ mp2 = 'mp2',
91
+ mp4 = 'mp4',
92
+ alac = 'alac',
93
+ amr = 'amr',
94
+ flac = 'flac',
95
+ opus = 'opus',
96
+ wav = 'wav',
97
+ }
98
+
99
+ export type AVEncodingType =
100
+ | AVEncodingOption.lpcm
101
+ | AVEncodingOption.ima4
102
+ | AVEncodingOption.aac
103
+ | AVEncodingOption.MAC3
104
+ | AVEncodingOption.MAC6
105
+ | AVEncodingOption.ulaw
106
+ | AVEncodingOption.alaw
107
+ | AVEncodingOption.mp1
108
+ | AVEncodingOption.mp2
109
+ | AVEncodingOption.mp4
110
+ | AVEncodingOption.alac
111
+ | AVEncodingOption.amr
112
+ | AVEncodingOption.flac
113
+ | AVEncodingOption.opus
114
+ | AVEncodingOption.wav;
115
+
116
+ export enum AVModeIOSOption {
117
+ gamechat = 'gamechat',
118
+ measurement = 'measurement',
119
+ movieplayback = 'movieplayback',
120
+ spokenaudio = 'spokenaudio',
121
+ videochat = 'videochat',
122
+ videorecording = 'videorecording',
123
+ voicechat = 'voicechat',
124
+ voiceprompt = 'voiceprompt',
125
+ }
126
+
127
+ export type AVModeIOSType =
128
+ | AVModeIOSOption.gamechat
129
+ | AVModeIOSOption.measurement
130
+ | AVModeIOSOption.movieplayback
131
+ | AVModeIOSOption.spokenaudio
132
+ | AVModeIOSOption.videochat
133
+ | AVModeIOSOption.videorecording
134
+ | AVModeIOSOption.voicechat
135
+ | AVModeIOSOption.voiceprompt;
136
+
137
+ export enum AVEncoderAudioQualityIOSType {
138
+ min = 0,
139
+ low = 32,
140
+ medium = 64,
141
+ high = 96,
142
+ max = 127,
143
+ }
144
+
145
+ export enum AVLinearPCMBitDepthKeyIOSType {
146
+ 'bit8' = 8,
147
+ 'bit16' = 16,
148
+ 'bit24' = 24,
149
+ 'bit32' = 32,
150
+ }
151
+
152
+ export interface AudioSet {
153
+ AVSampleRateKeyIOS?: number;
154
+ AVFormatIDKeyIOS?: AVEncodingType;
155
+ AVModeIOS?: AVModeIOSType;
156
+ AVNumberOfChannelsKeyIOS?: number;
157
+ AVEncoderAudioQualityKeyIOS?: AVEncoderAudioQualityIOSType;
158
+ AVLinearPCMBitDepthKeyIOS?: AVLinearPCMBitDepthKeyIOSType;
159
+ AVLinearPCMIsBigEndianKeyIOS?: boolean;
160
+ AVLinearPCMIsFloatKeyIOS?: boolean;
161
+ AVLinearPCMIsNonInterleavedIOS?: boolean;
162
+ AVEncoderBitRateKeyIOS?: number;
163
+ OutputFormatAndroid?: OutputFormatAndroidType;
164
+ AudioEncoderAndroid?: AudioEncoderAndroidType;
165
+ AudioEncodingBitRateAndroid?: number;
166
+ AudioSamplingRateAndroid?: number;
167
+ AudioChannelsAndroid?: number;
168
+ AudioSourceAndroid?: AudioSourceAndroidType;
169
+ AudioSourceHarmony?: AudioSourceHarmonyType;
170
+ AudioMimeHarmony?: AudioMimeHarmonyType;
171
+ AudioFileFormatHarmony?: AudioFormatHarmonyType;
172
+ /**
173
+ * 音频编码比特率,选择音频录制时必填。
174
+
175
+ 支持范围:
176
+
177
+ - AAC编码格式支持比特率范围[32000 - 500000]。
178
+
179
+ - G711-mulaw编码格式支持比特率范围[64000 - 64000]。
180
+
181
+ - MP3编码格式支持范围[8000, 16000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000]。
182
+
183
+ 当使用MP3编码格式时,采样率和比特率的映射关系:
184
+
185
+ - 采样率使用16K以下时,对应比特率范围为[8kbps - 64kbps]。
186
+
187
+ - 采样率使用16K~32K时对应的比特率范围为[8kbps - 160kbps]。
188
+
189
+ - 采样率使用32K以上时对应的比特率范围为[32kbps - 320kbps]。
190
+ */
191
+ AudioEncodingBitRateHarmony?: number;
192
+ /**
193
+ * 支持范围:
194
+
195
+ - AAC编码支持采样率范围[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000]。
196
+
197
+ - G711-mulaw编码支持采样率范围[8000 - 8000]。
198
+
199
+ - MP3编码支持采样率范围[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]。
200
+ */
201
+ AudioSamplingRateHarmony?: number;
202
+ /**
203
+ * 音频采集声道数
204
+
205
+ - AAC编码格式支持范围[1 - 8]。
206
+
207
+ - G711-mulaw编码格式支持范围[1 - 1]。
208
+
209
+ - MP3编码格式支持范围[1 - 2]
210
+ */
211
+ AudioChannelsHarmony?: number;
212
+ }
213
+
214
+ export type RecordBackType = {
215
+ isRecording?: boolean;
216
+ currentPosition: number;
217
+ currentMetering?: number;
218
+ };
219
+
220
+ export type PlayBackType = {
221
+ isMuted?: boolean;
222
+ currentPosition: number;
223
+ duration: number;
224
+ isFinished: boolean;
225
+ };
226
+