@react-native-ohos/react-native-audio 4.2.3-rc.1 → 4.2.3-rc.3

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.
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-audio",
4
+ "License": "MIT License",
5
+ "License File": "https://github.com/jsierles/react-native-audio/blob/master/LICENSE",
6
+ "Version Number": "4.2.2",
7
+ "Owner" : "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/jsierles/react-native-audio",
9
+ "Description": "Audio recorder library for React Native"
10
+ }
11
+ ]
package/README.md CHANGED
@@ -11,5 +11,5 @@ This project is based on [react-native-audio](https://github.com/jsierles/react-
11
11
 
12
12
  ## License
13
13
 
14
- This library is licensed under [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_react-native-audio/blob/master/LICENSE).
14
+ This library is licensed under [The MIT License (MIT)](https://gitcode.com/openharmony-sig/rntpc_react-native-audio/blob/master/LICENSE).
15
15
 
@@ -5,7 +5,7 @@
5
5
  description: '',
6
6
  main: 'index.ets',
7
7
  type: 'module',
8
- version: '4.2.3-rc.1',
8
+ version: '4.2.3-rc.3',
9
9
  dependencies: {
10
10
  "@rnoh/react-native-openharmony": "^0.72.38"
11
11
  },
@@ -64,16 +64,16 @@ export class AudioRecordManager {
64
64
  async prepareRecordingAtPath(path: string, options: RecordingOptions): Promise<void> {
65
65
  if (this.isRecording) {
66
66
  this.logger.error('Please call stopRecording before starting recording.');
67
- return;
67
+ return Promise.reject('Please call stopRecording before starting recording.')
68
68
  }
69
69
  if (path === '') {
70
70
  this.logger.error('Invalid path.');
71
- return;
71
+ return Promise.reject('Invalid path.')
72
72
  }
73
73
  const isAuthorization = await this.checkAuthorizationStatus();
74
74
  if (!isAuthorization) {
75
75
  this.logger.error('Please obtain microphone authorization first.');
76
- return;
76
+ return Promise.reject('Please obtain microphone authorization first.')
77
77
  }
78
78
  try {
79
79
  //创建录制实例
@@ -102,15 +102,12 @@ export class AudioRecordManager {
102
102
  this.file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
103
103
  this.avConfig.url = `fd://${this.file.fd}`;
104
104
  this.includeBase64 = options.IncludeBase64;
105
- await this.avRecorder.prepare(this.avConfig).then((res) => {
106
- this.logger.info(`${res}.`);
107
- }).catch((err) => {
108
- this.logger.error(`${err}.`);
109
- });
105
+ await this.avRecorder.prepare(this.avConfig)
110
106
  this.logger.info(`Recording is prepared.`);
111
107
  this.logger.debug('Recording is prepared.');
112
108
  } catch (error) {
113
109
  this.logger.error(`${JSON.stringify(error)}.`);
110
+ return Promise.reject(error)
114
111
  }
115
112
  }
116
113
 
@@ -150,6 +147,7 @@ export class AudioRecordManager {
150
147
  }
151
148
  } catch (error) {
152
149
  this.logger.error(`requestPermissionsFromUser failed, code is ${error?.code}, message is ${error?.message}.`);
150
+ return Promise.reject(error)
153
151
  }
154
152
  }
155
153
 
@@ -165,17 +163,19 @@ export class AudioRecordManager {
165
163
  tokenId = appInfo.accessTokenId;
166
164
  } catch (error) {
167
165
  this.logger.error(`getBundleInfoForSelf failed, code is ${error?.code}, message is ${error?.message}.`);
166
+ return Promise.reject(error)
168
167
  }
169
168
  //检查应用是否被授予权限
170
169
  try {
171
170
  grantStatus = await atManager.checkAccessToken(tokenId, permission);
172
171
  } catch (error) {
173
172
  this.logger.error(`checkAccessToken failed, code is ${error?.code}, message is ${error?.message}.`);
173
+ return Promise.reject(error)
174
174
  }
175
175
  return grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED;
176
176
  }
177
177
 
178
- //格式化音频输入源
178
+ //格式化音频输入源
179
179
  getAudioSourceFormatString(audioSource: number) {
180
180
  switch (audioSource) {
181
181
  case 0:
@@ -202,8 +202,12 @@ export class AudioRecordManager {
202
202
  //格式化封装格式,当前仅支持m4a
203
203
  getFileFormatFormatString(fileFormat: string) {
204
204
  switch (fileFormat) {
205
- case 'm4a':
206
- return media.ContainerFormatType.CFT_MPEG_4A;
205
+ case 'aac':
206
+ if (media.ContainerFormatType["CFT_AAC"]) {
207
+ return media.ContainerFormatType["CFT_AAC"];
208
+ } else {
209
+ return media.ContainerFormatType.CFT_MPEG_4A;
210
+ }
207
211
  default:
208
212
  this.logger.debug(`Using media.ContainerFormatType.CFT_MPEG_4A : ${media.ContainerFormatType.CFT_MPEG_4A}.`);
209
213
  return media.ContainerFormatType.CFT_MPEG_4A;
@@ -215,11 +219,12 @@ export class AudioRecordManager {
215
219
  try {
216
220
  if (this.avRecorder.state === AVRecorderStateEnum.STARTED || this.avRecorder.state === AVRecorderStateEnum.PAUSED) {
217
221
  this.logger.error('Please call stopRecording before starting recording.');
218
- return;
222
+ return Promise.reject('Please call stopRecording before starting recording.')
223
+
219
224
  }
220
225
  if (this.avRecorder.state !== AVRecorderStateEnum.PREPARED) {
221
226
  this.logger.error('Please call prepareRecording before starting recording.');
222
- return;
227
+ return Promise.reject('Please call prepareRecording before starting recording.')
223
228
  }
224
229
  await this.avRecorder.start();
225
230
  this.isRecording = true;
@@ -230,6 +235,7 @@ export class AudioRecordManager {
230
235
  this.startTimer();
231
236
  } catch (error) {
232
237
  this.logger.error(`startRecording failed, code is ${error?.code}, message is ${error?.message}.`);
238
+ return Promise.reject(error)
233
239
  }
234
240
  }
235
241
 
@@ -242,10 +248,11 @@ export class AudioRecordManager {
242
248
  this.logger.debug('pause recording.');
243
249
  } catch (error) {
244
250
  this.logger.error(`pauseRecording failed, code is ${error?.code}, message is ${error?.message}.`);
251
+ return Promise.reject(error)
245
252
  }
246
253
  } else {
247
254
  this.logger.error('It is reasonable to call pauseRecording only in the started state.');
248
- return;
255
+ return Promise.reject('It is reasonable to call pauseRecording only in the started state.')
249
256
  }
250
257
  }
251
258
 
@@ -258,10 +265,11 @@ export class AudioRecordManager {
258
265
  this.logger.debug('resume recording.');
259
266
  } catch (error) {
260
267
  this.logger.error(`resumeRecording failed. code is ${error?.code}, message is ${error?.message}.`);
268
+ return Promise.reject(`resumeRecording failed. code is ${error?.code}, message is ${error?.message}.`)
261
269
  }
262
270
  } else {
263
271
  this.logger.error('It is reasonable to call resumeRecording only in the paused state.');
264
- return;
272
+ return Promise.reject('It is reasonable to call resumeRecording only in the paused state.')
265
273
  }
266
274
  }
267
275
 
@@ -288,7 +296,7 @@ export class AudioRecordManager {
288
296
  }
289
297
  } else {
290
298
  this.logger.error('It is reasonable to call stopRecording only in the started or paused state.');
291
- return;
299
+ return Promise.reject('It is reasonable to call stopRecording only in the started or paused state.')
292
300
  }
293
301
  }
294
302
 
package/harmony/audio.har CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-audio",
3
- "version": "4.2.3-rc.1",
3
+ "version": "4.2.3-rc.3",
4
4
  "description": "React Native extension for recording audio",
5
5
  "main": "index.js",
6
6
  "author": "Joshua Sierles <joshua@diluvia.net> (https://github.com/jsierles)",
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "https://gitee.com/openharmony-sig/rntpc_react-native-audio"
24
+ "url": "https://gitcode.com/openharmony-sig/rntpc_react-native-audio"
25
25
  },
26
26
  "scripts": {
27
27
  "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-audio --cpp-output-path ./harmony/audio/src/main/cpp/generated --ets-output-path ./harmony/audio/src/main/ets/generated --turbo-modules-spec-paths ./NativeAudio.ts "