@react-native-ohos/react-native-audio-recorder-player 3.7.1 → 3.7.2
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 +21 -0
- package/README.md +82 -5
- package/harmony/audio_recorder_player/BuildProfile.ets +1 -1
- package/harmony/audio_recorder_player/oh-package.json5 +1 -1
- package/harmony/audio_recorder_player/src/main/ets/RNAudioRecorderPlayerTurboModule.ts +32 -26
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +23 -18
- package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +7 -1
- package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +4 -8
- package/harmony/audio_recorder_player.har +0 -0
- package/package.json +12 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 鸿蒙化Log
|
|
4
|
+
### v3.7.2
|
|
5
|
+
- release:@react-native-ohos/react-native-audio-recorder-player@3.7.2 [#50](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/50)
|
|
6
|
+
- fix:The problem of file not being overwritten when recording again with the same file name modified [#45](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/45)
|
|
7
|
+
- fix: modify quality hardening bug for master update [#47](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/47)
|
|
8
|
+
|
|
9
|
+
### v3.7.1
|
|
10
|
+
- release version v3.7.1 [#39](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/39)
|
|
11
|
+
- docs: update readme [#36](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/36)
|
|
12
|
+
- docs: 更新82 react-native-audio-recorder-player中英文文档 [#33](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/33)
|
|
13
|
+
- feat: 82适配以及支持autolink [#27](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/27)
|
|
14
|
+
- merge:同步77分支代码到master分支 [#25](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/25)
|
|
15
|
+
- merge:同步77分支代码到master分支 [#26](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/26)
|
|
16
|
+
- docs: 更新readme [#28](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/28)
|
|
17
|
+
- fix:把遗漏的封装格式AAC补齐 [#22](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/22)
|
|
18
|
+
|
|
19
|
+
### v3.7.0
|
|
20
|
+
- release:@react-native-ohos/react-native-audio-recorder-player@3.7.0 [#20](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/20)
|
|
21
|
+
|
package/README.md
CHANGED
|
@@ -617,7 +617,7 @@ class Page extends Component<any, State> {
|
|
|
617
617
|
AudioSourceHarmony: AudioSourceHarmonyType.MIC,
|
|
618
618
|
AudioMimeHarmony: AudioMimeHarmonyType.AUDIO_AAC,
|
|
619
619
|
AudioFileFormatHarmony: AudioFormatHarmonyType.MPEG_4A,
|
|
620
|
-
AudioEncodingBitRateHarmony:
|
|
620
|
+
AudioEncodingBitRateHarmony: 128000,
|
|
621
621
|
AudioSamplingRateHarmony: 44100,
|
|
622
622
|
AudioChannelsHarmony: 2,
|
|
623
623
|
};
|
|
@@ -769,9 +769,9 @@ this.audioRecorderPlayer.mmss(
|
|
|
769
769
|
|
|
770
770
|
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|
|
771
771
|
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | -------- | ----------------- |
|
|
772
|
-
| `mmss` |
|
|
773
|
-
| `mmssss` | 将毫秒转换为“分钟:秒:毫秒”格式的字符串 | function(
|
|
774
|
-
| `setSubscriptionDuration` | 设置录音器或播放器启动时的默认回调时间间隔。默认为 0.5,即 500 毫秒。| function(
|
|
772
|
+
| `mmss` | 将秒转换为“分:秒”格式的字符串 | function(seconds:number): string | No | Android,iOS | yes |
|
|
773
|
+
| `mmssss` | 将毫秒转换为“分钟:秒:毫秒”格式的字符串 | function(milisecs:number): string | No | Android,iOS | yes |
|
|
774
|
+
| `setSubscriptionDuration` | 设置录音器或播放器启动时的默认回调时间间隔。默认为 0.5,即 500 毫秒。| function(sec:number):Promise<string> | No | Android,iOS | yes |
|
|
775
775
|
| `addRecordBackListener` |从原生模块获取回调。将接收 currentPosition、currentMetering(如果在 startRecorder 中进行了配置)。 | function(callBack:(value:RecordBackType)=>void): void | No | Android,iOS | yes |
|
|
776
776
|
| `removeRecordBackListener` |移除 recordBack 监听器。 | function(): void | No | Android,iOS | yes |
|
|
777
777
|
| `addPlayBackListener` | 从原生模块获取回调,将收到 duration 和 currentPosition。 | function(callBack:(value: PlayBackType)=>void): void | No | Android,iOS | yes |
|
|
@@ -784,10 +784,87 @@ this.audioRecorderPlayer.mmss(
|
|
|
784
784
|
| `stopPlayer` | 停止播放。 | function() : Promise< string > | No | Android,iOS | yes |
|
|
785
785
|
| `pausePlayer` | 暂停播放。 | function() : Promise< string > | No | Android,iOS | yes |
|
|
786
786
|
| `resumePlayer` | 恢复播放。 | function() : Promise< string > | No | Android,iOS | yes |
|
|
787
|
-
| `seekToPlayer` | 音频跳转。 | function(
|
|
787
|
+
| `seekToPlayer` | 音频跳转。 | function(time:number) : Promise< string > | No | Android,iOS | yes |
|
|
788
788
|
| `setVolume` | 设置音频播放器的音量(默认值为 1.0,取值范围:0.0 ~ 1.0)。 | function(volume:float) : Promise< string > | No | Android,iOS | yes |
|
|
789
789
|
| `setPlaybackSpeed` | 设置播放速度。<br/>鸿蒙化后仅支持0.125、0.25、0.5、0.75、1、1.25、1.5、1.75、2和3倍速设置,其中3倍速仅在API version 13开始支持。 | function(playbackSpeed: number): Promise< string > | No | Android,iOS | partially (3倍速仅在API version 13开始支持) |
|
|
790
790
|
|
|
791
|
+
## 鸿蒙平台 AudioSet 属性说明
|
|
792
|
+
|
|
793
|
+
在 `startRecorder` 方法中使用的 `AudioSet` 对象包含多个平台的配置属性,其中以 `Harmony` 后缀结尾的属性为鸿蒙平台专属配置。以下对鸿蒙平台相关的枚举类型和属性进行详细说明。
|
|
794
|
+
|
|
795
|
+
### AudioSourceHarmonyType(音频输入源类型)
|
|
796
|
+
|
|
797
|
+
用于设置录音时的音频输入源,通过 `AudioSet.AudioSourceHarmony` 属性配置。
|
|
798
|
+
|
|
799
|
+
| 枚举值 | 对应数值 | 说明 |
|
|
800
|
+
| --------------------- | -------- | ----------------------------------- |
|
|
801
|
+
| `DEFAULT` | 0 | 默认音频源 |
|
|
802
|
+
| `MIC` | 1 | 麦克风输入 |
|
|
803
|
+
| `VOICE_RECOGNITION` | 2 | 语音识别,适用于语音转文字等场景 |
|
|
804
|
+
| `VOICE_COMMUNICATION` | 7 | 语音通信,适用于 VoIP 等实时通话场景 |
|
|
805
|
+
| `VOICE_MESSAGE` | 10 | 语音消息,适用于录制语音短消息 |
|
|
806
|
+
| `CAMCORDER` | 12 | 摄像头录音,与视频同步录制音频 |
|
|
807
|
+
|
|
808
|
+
### AudioMimeHarmonyType(音频 MIME 类型)
|
|
809
|
+
|
|
810
|
+
用于设置录音的音频编码格式 MIME 类型,通过 `AudioSet.AudioMimeHarmony` 属性配置。
|
|
811
|
+
|
|
812
|
+
| 枚举值 | 对应值 | 说明 |
|
|
813
|
+
| --------------- | ----------------- | ----------------------------- |
|
|
814
|
+
| `AUDIO_AAC` | `audio/mp4a-latm` | AAC 编码格式(音频/mp4a-latm) |
|
|
815
|
+
| `AUDIO_VORBIS` | `audio/vorbis` | Vorbis 编码格式 |
|
|
816
|
+
| `AUDIO_FLAC` | `audio/flac` | FLAC 无损编码格式 |
|
|
817
|
+
| `AUDIO_MP3` | `audio/mpeg` | MP3 编码格式 |
|
|
818
|
+
| `AUDIO_G711MU` | `audio/g711mu` | G711-mulaw 编码格式 |
|
|
819
|
+
|
|
820
|
+
### AudioFormatHarmonyType(音频文件格式类型)
|
|
821
|
+
|
|
822
|
+
用于设置录音输出的音频文件格式(后缀名),通过 `AudioSet.AudioFileFormatHarmony` 属性配置。
|
|
823
|
+
|
|
824
|
+
| 枚举值 | 对应值 | 说明 |
|
|
825
|
+
| --------- | ------ | ----------------------------- |
|
|
826
|
+
| `MPEG_4` | `mp4` | MPEG-4 容器格式(.mp4 文件) |
|
|
827
|
+
| `MPEG_4A` | `m4a` | MPEG-4 音频格式(.m4a 文件) |
|
|
828
|
+
| `MP3` | `mp3` | MP3 格式(.mp3 文件) |
|
|
829
|
+
| `WAV` | `wav` | WAV 格式(.wav 文件) |
|
|
830
|
+
| `AAC` | `aac` | AAC 格式(.aac 文件) |
|
|
831
|
+
|
|
832
|
+
### AudioSet 鸿蒙专属属性说明
|
|
833
|
+
|
|
834
|
+
| 属性名 | 类型 | 说明 |
|
|
835
|
+
| ----------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
836
|
+
| `AudioSourceHarmony` | `AudioSourceHarmonyType` | 音频输入源类型。用于指定录音时的音频来源,默认为 `MIC`(麦克风)。 |
|
|
837
|
+
| `AudioMimeHarmony` | `AudioMimeHarmonyType` | 音频编码格式(MIME 类型)。用于指定录音的音频编码方式,如 AAC、MP3、FLAC 等。需与对应的采样率、比特率、声道数范围匹配。 |
|
|
838
|
+
| `AudioFileFormatHarmony` | `AudioFormatHarmonyType` | 音频文件输出格式。用于指定录音文件的容器格式及后缀名,如 `m4a`、`mp3`、`wav` 等。 |
|
|
839
|
+
| `AudioEncodingBitRateHarmony` | `number` | 音频编码比特率(单位:bps)。选择音频录制时必填。支持范围:<br>- AAC 编码格式支持比特率范围 `[32000 - 500000]`<br>- G711-mulaw 编码格式支持比特率范围 `[64000 - 64000]`<br>- MP3 编码格式支持 `[8000, 16000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000]` |
|
|
840
|
+
| `AudioSamplingRateHarmony` | `number` | 音频采样率(单位:Hz)。支持范围:<br>- AAC 编码支持采样率范围 `[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000]`<br>- G711-mulaw 编码支持采样率范围 `[8000 - 8000]`<br>- MP3 编码支持采样率范围 `[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]` |
|
|
841
|
+
| `AudioChannelsHarmony` | `number` | 音频采集声道数。支持范围:<br>- AAC 编码格式支持范围 `[1 - 8]`<br>- G711-mulaw 编码格式支持范围 `[1 - 1]`<br>- MP3 编码格式支持范围 `[1 - 2]` |
|
|
842
|
+
|
|
843
|
+
> [!TIP] 在使用 MP3 编码格式时,采样率和比特率存在映射关系:采样率 16K 以下时对应比特率范围为 `[8kbps - 64kbps]`;采样率 16K~32K 时对应比特率范围为 `[8kbps - 160kbps]`;采样率 32K 以上时对应比特率范围为 `[32kbps - 320kbps]`。
|
|
844
|
+
|
|
845
|
+
### 使用示例
|
|
846
|
+
|
|
847
|
+
```javascript
|
|
848
|
+
import {
|
|
849
|
+
AudioMimeHarmonyType,
|
|
850
|
+
AudioFormatHarmonyType,
|
|
851
|
+
AudioSourceHarmonyType,
|
|
852
|
+
AudioSet
|
|
853
|
+
} from 'react-native-audio-recorder-player';
|
|
854
|
+
|
|
855
|
+
const audioSet: AudioSet = {
|
|
856
|
+
// 鸿蒙平台录音配置
|
|
857
|
+
AudioSourceHarmony: AudioSourceHarmonyType.MIC, // 使用麦克风作为音频输入源
|
|
858
|
+
AudioMimeHarmony: AudioMimeHarmonyType.AUDIO_AAC, // 使用 AAC 编码格式
|
|
859
|
+
AudioFileFormatHarmony: AudioFormatHarmonyType.MPEG_4A, // 输出为 m4a 格式文件
|
|
860
|
+
AudioEncodingBitRateHarmony: 128000, // 设置编码比特率为 128000 bps
|
|
861
|
+
AudioSamplingRateHarmony: 44100, // 设置采样率为 44100 Hz
|
|
862
|
+
AudioChannelsHarmony: 2, // 设置双声道录制
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
const uri = await this.audioRecorderPlayer.startRecorder('audio.m4a', audioSet);
|
|
866
|
+
```
|
|
867
|
+
|
|
791
868
|
## 遗留问题
|
|
792
869
|
无
|
|
793
870
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
3
|
*/
|
|
4
|
-
export const HAR_VERSION = '3.7.
|
|
4
|
+
export const HAR_VERSION = '3.7.2';
|
|
5
5
|
export const BUILD_MODE_NAME = 'debug';
|
|
6
6
|
export const DEBUG = true;
|
|
7
7
|
export const TARGET_NAME = 'default';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "@react-native-ohos/react-native-audio-recorder-player",
|
|
6
6
|
"description": "",
|
|
7
7
|
"main": "index.ets",
|
|
8
|
-
"version": "3.7.
|
|
8
|
+
"version": "3.7.2",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
|
|
11
11
|
},
|
|
@@ -41,10 +41,6 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
41
41
|
private PlayBackListenerTimer;
|
|
42
42
|
private meteringEnabled: boolean = false;
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* Set listerner from native module for recorder.
|
|
46
|
-
* @returns {callBack((e: RecordBackType): void)}
|
|
47
|
-
*/
|
|
48
44
|
constructor(ctx: AnyThreadTurboModuleContext) {
|
|
49
45
|
super(ctx);
|
|
50
46
|
this.AVRecorderInstance = new Recorder(ctx.uiAbilityContext);
|
|
@@ -65,8 +61,8 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @returns {void}
|
|
64
|
+
* Set listerner from native module for recorder.
|
|
65
|
+
* @returns {callBack((e: RecordBackType): void)}
|
|
70
66
|
*/
|
|
71
67
|
public addRecordBackListener(): void {
|
|
72
68
|
if (this.RecordBackListenerTimer) {
|
|
@@ -100,19 +96,20 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
100
96
|
}, this.subscriptionDuration);
|
|
101
97
|
});
|
|
102
98
|
}
|
|
103
|
-
|
|
99
|
+
|
|
104
100
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @returns {
|
|
101
|
+
* Remove listener for recorder.
|
|
102
|
+
* @returns {void}
|
|
107
103
|
*/
|
|
108
104
|
public removeRecordBackListener(): void {
|
|
109
105
|
clearInterval(this.RecordBackListenerTimer);
|
|
110
106
|
this.RecordBackListenerTimer = null;
|
|
107
|
+
this.AVRecorderInstance.clearStartRecordCallback();
|
|
111
108
|
}
|
|
112
109
|
|
|
113
110
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @returns {void}
|
|
111
|
+
* Set listener from native module for player.
|
|
112
|
+
* @returns {callBack((e: PlayBackType): void)}
|
|
116
113
|
*/
|
|
117
114
|
public addPlayBackListener(): void {
|
|
118
115
|
if (this.PlayBackListenerTimer) {
|
|
@@ -134,9 +131,14 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
134
131
|
});
|
|
135
132
|
}
|
|
136
133
|
|
|
134
|
+
/**
|
|
135
|
+
* remove listener for player.
|
|
136
|
+
* @returns {void}
|
|
137
|
+
*/
|
|
137
138
|
public removePlayBackListener(): void {
|
|
138
139
|
clearInterval(this.PlayBackListenerTimer);
|
|
139
140
|
this.PlayBackListenerTimer = null;
|
|
141
|
+
this.AVPlayerInstance.mapClear();
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
@@ -152,6 +154,10 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
152
154
|
if (this.isRecording()) {
|
|
153
155
|
return Promise.reject(processValue.play);
|
|
154
156
|
}
|
|
157
|
+
|
|
158
|
+
if (!!!uri) {
|
|
159
|
+
return Promise.reject('empty uri');
|
|
160
|
+
}
|
|
155
161
|
this.meteringEnabled = meteringEnabled === true ? true : false;
|
|
156
162
|
const profile: media.AVRecorderProfile = this.getAudioSets(audioSets);
|
|
157
163
|
this.AVRecorderInstance.setAVProfile(profile, audioSets?.AudioSourceHarmony as number as media.AudioSourceType);
|
|
@@ -221,6 +227,11 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
221
227
|
return Promise.reject(processValue.stateError);
|
|
222
228
|
}
|
|
223
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Start playing with param.
|
|
232
|
+
* @param {string} uri audio uri.
|
|
233
|
+
* @returns {Promise<string>}
|
|
234
|
+
*/
|
|
224
235
|
public async startPlayer(uri?: string, httpHeaders?: Record<string, string>): Promise<string> {
|
|
225
236
|
if (this.AVPlayerInstance.PlayerState === AVPlayerState.paused) {
|
|
226
237
|
return this.resumePlayer();
|
|
@@ -231,8 +242,7 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
231
242
|
}
|
|
232
243
|
|
|
233
244
|
/**
|
|
234
|
-
*
|
|
235
|
-
* @param {string} uri audio uri.
|
|
245
|
+
* Resume playing.
|
|
236
246
|
* @returns {Promise<string>}
|
|
237
247
|
*/
|
|
238
248
|
public async resumePlayer(): Promise<string> {
|
|
@@ -243,8 +253,8 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
243
253
|
return Promise.reject(processValue.stateError);
|
|
244
254
|
}
|
|
245
255
|
|
|
246
|
-
|
|
247
|
-
*
|
|
256
|
+
/**
|
|
257
|
+
* Stop playing.
|
|
248
258
|
* @returns {Promise<string>}
|
|
249
259
|
*/
|
|
250
260
|
public async stopPlayer(): Promise<string> {
|
|
@@ -252,8 +262,8 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
252
262
|
return this.AVPlayerInstance.stopPlayeringProcess();
|
|
253
263
|
}
|
|
254
264
|
|
|
255
|
-
|
|
256
|
-
*
|
|
265
|
+
/**
|
|
266
|
+
* Pause playing.
|
|
257
267
|
* @returns {Promise<string>}
|
|
258
268
|
*/
|
|
259
269
|
public async pausePlayer(): Promise<string> {
|
|
@@ -265,7 +275,8 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
265
275
|
}
|
|
266
276
|
|
|
267
277
|
/**
|
|
268
|
-
*
|
|
278
|
+
* Seek to.
|
|
279
|
+
* @param {number} time position seek to in millisecond.
|
|
269
280
|
* @returns {Promise<string>}
|
|
270
281
|
*/
|
|
271
282
|
public async seekToPlayer(time: number): Promise<string> {
|
|
@@ -275,9 +286,9 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
275
286
|
return this.AVPlayerInstance.seekToPlayer(time);
|
|
276
287
|
}
|
|
277
288
|
|
|
278
|
-
|
|
279
|
-
*
|
|
280
|
-
* @param {number}
|
|
289
|
+
/**
|
|
290
|
+
* Set volume.
|
|
291
|
+
* @param {number} setVolume set volume.
|
|
281
292
|
* @returns {Promise<string>}
|
|
282
293
|
*/
|
|
283
294
|
async setVolume(volume: number): Promise<string> {
|
|
@@ -305,11 +316,6 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
305
316
|
return this.AVPlayerInstance.setPlaybackSpeed(playbackSpeed);
|
|
306
317
|
}
|
|
307
318
|
|
|
308
|
-
/**
|
|
309
|
-
* Set volume.
|
|
310
|
-
* @param {number} setVolume set volume.
|
|
311
|
-
* @returns {Promise<string>}
|
|
312
|
-
*/
|
|
313
319
|
async setSubscriptionDuration(sec: number): Promise<string> {
|
|
314
320
|
const milliseconds = sec * 1000;
|
|
315
321
|
this.subscriptionDuration = milliseconds;
|
|
@@ -44,6 +44,12 @@ export default class Player {
|
|
|
44
44
|
this.AudioAsset = new SaveAudioAsset(TAG, context);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
public mapClear() {
|
|
48
|
+
if (this.EventMap?.has(EventTarget.timeUpdate)) {
|
|
49
|
+
this.EventMap.delete(EventTarget.timeUpdate);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
public onEvent(name: string, callback: () => void) {
|
|
48
54
|
if (this.EventMap.has(name)) {
|
|
49
55
|
return;
|
|
@@ -154,11 +160,10 @@ export default class Player {
|
|
|
154
160
|
Logger.debug(TAG, ' resumePlayering called');
|
|
155
161
|
if (this.PlayerState === AVPlayerState.paused) {
|
|
156
162
|
Logger.debug(TAG, 'current state is paused, to resume');
|
|
157
|
-
this.seekToPlayerTime(this.currentPosition)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
163
|
+
await this.seekToPlayerTime(this.currentPosition);
|
|
164
|
+
this.getCurrentPosition();
|
|
165
|
+
this.audioPlayer.play();
|
|
166
|
+
return processValue.resume;
|
|
162
167
|
}
|
|
163
168
|
Logger.debug(TAG, ' resumePlayering done');
|
|
164
169
|
return processValue.stateError;
|
|
@@ -255,7 +260,7 @@ export default class Player {
|
|
|
255
260
|
.createAVPlayer()
|
|
256
261
|
.then((player) => {
|
|
257
262
|
Logger.debug(TAG, 'case createAVPlayer called');
|
|
258
|
-
if (!!
|
|
263
|
+
if (!!player) {
|
|
259
264
|
this.audioPlayer = player;
|
|
260
265
|
} else {
|
|
261
266
|
Logger.debug(TAG, 'case create avPlayer failed!!!');
|
|
@@ -293,6 +298,7 @@ export default class Player {
|
|
|
293
298
|
this.getDurationTime();
|
|
294
299
|
this.prepareAudioPlayer();
|
|
295
300
|
this.getCurrentPosition();
|
|
301
|
+
break;
|
|
296
302
|
}
|
|
297
303
|
case AVPlayerState.prepared: {
|
|
298
304
|
this.PlayerState = AVPlayerState.prepared;
|
|
@@ -317,7 +323,7 @@ export default class Player {
|
|
|
317
323
|
case AVPlayerState.completed: {
|
|
318
324
|
this.isPlaying = false;
|
|
319
325
|
this.audioPlayer.off(EventTarget.timeUpdate);
|
|
320
|
-
//
|
|
326
|
+
// completed 执行完成后执行stopped
|
|
321
327
|
}
|
|
322
328
|
case AVPlayerState.stopped: {
|
|
323
329
|
this.PlayerState = AVPlayerState.stopped;
|
|
@@ -367,6 +373,7 @@ export default class Player {
|
|
|
367
373
|
this.audioPlayer.url = fdPath + lastUrl;
|
|
368
374
|
return;
|
|
369
375
|
}
|
|
376
|
+
this.playUrl = ''; // 清空无效地址
|
|
370
377
|
Logger.error(TAG, 'this uri is not allowed');
|
|
371
378
|
return Promise.reject('this uri is not allowed');
|
|
372
379
|
}
|
|
@@ -392,20 +399,14 @@ export default class Player {
|
|
|
392
399
|
isExist = fs.accessSync(`${path}/${'sound.m4a'}`);
|
|
393
400
|
}
|
|
394
401
|
if (isExist) {
|
|
395
|
-
|
|
402
|
+
if (url && url === 'DEFAULT') {
|
|
403
|
+
this.playUrl = `${path}/${'sound.m4a'}`;
|
|
404
|
+
} else {
|
|
405
|
+
this.playUrl = `${path}/${url}`;
|
|
406
|
+
}
|
|
396
407
|
const file = fs.openSync(this.playUrl);
|
|
397
408
|
return file.fd;
|
|
398
409
|
} else {
|
|
399
|
-
const fileList: string[] = fs.listFileSync(path) ?? [];
|
|
400
|
-
const audioList = fileList.filter((item: string) => item.endsWith(media.ContainerFormatType.CFT_MPEG_4A));
|
|
401
|
-
const last = audioList.pop();
|
|
402
|
-
Logger.debug(TAG, last);
|
|
403
|
-
if (last) {
|
|
404
|
-
this.playUrl = `${path}/${last}`;
|
|
405
|
-
const file = fs.openSync(this.playUrl);
|
|
406
|
-
Logger.debug(TAG, 'last file path ', last);
|
|
407
|
-
return file.fd;
|
|
408
|
-
}
|
|
409
410
|
return null;
|
|
410
411
|
}
|
|
411
412
|
}
|
|
@@ -459,6 +460,10 @@ export default class Player {
|
|
|
459
460
|
}, this.failureCallback)
|
|
460
461
|
.catch(this.catchCallback);
|
|
461
462
|
this.audioPlayer = undefined;
|
|
463
|
+
|
|
464
|
+
if (this.EventMap) {
|
|
465
|
+
this.EventMap.clear()
|
|
466
|
+
}
|
|
462
467
|
}
|
|
463
468
|
}
|
|
464
469
|
}
|
|
@@ -30,7 +30,7 @@ export default class Recorder {
|
|
|
30
30
|
private mFileAssetId: number;
|
|
31
31
|
private avProfile: media.AVRecorderProfile;
|
|
32
32
|
private avConfig: media.AVRecorderConfig;
|
|
33
|
-
private startRecordCallback: () => void;
|
|
33
|
+
private startRecordCallback: (() => void) | null = null;
|
|
34
34
|
private context: common.UIAbilityContext;
|
|
35
35
|
|
|
36
36
|
constructor(context: common.UIAbilityContext) {
|
|
@@ -38,6 +38,12 @@ export default class Recorder {
|
|
|
38
38
|
this.mSaveAudioAsset = new SaveAudioAsset(TAG, context);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
clearStartRecordCallback() {
|
|
42
|
+
if(this.startRecordCallback) {
|
|
43
|
+
this.startRecordCallback = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
public setAVProfile(newValue: media.AVRecorderProfile, audioSource?: media.AudioSourceType) {
|
|
42
48
|
this.avProfile = {
|
|
43
49
|
...avProfile,
|
|
@@ -82,14 +82,10 @@ export default class SaveCameraAsset {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
private createOrOpen(path: string): fs.File {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} else {
|
|
90
|
-
file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
|
91
|
-
}
|
|
92
|
-
return file;
|
|
85
|
+
return fs.openSync(
|
|
86
|
+
path,
|
|
87
|
+
fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC,
|
|
88
|
+
);
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
private checkName(name: string): string {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-ohos/react-native-audio-recorder-player",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"description": "React Native Audio Recorder and Player.",
|
|
5
5
|
"homepage": "https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"postinstall": "dooboolab-welcome postinstall",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"test:coverage": "jest --config jest/jest.config.js --coverage",
|
|
11
12
|
"build": "tsc && flowgen index.d.ts -o index.js.flow",
|
|
12
13
|
"lint": "eslint -c .eslintrc.js 'index.ts'",
|
|
13
14
|
"pack": "npm pack --ignore-scripts"
|
|
@@ -41,9 +42,10 @@
|
|
|
41
42
|
"files": [
|
|
42
43
|
"src",
|
|
43
44
|
"harmony",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"!build"
|
|
45
|
+
"index.ts",
|
|
46
|
+
"index.d.ts",
|
|
47
|
+
"!build",
|
|
48
|
+
"CHANGELOG.md"
|
|
47
49
|
],
|
|
48
50
|
"author": "dooboolab",
|
|
49
51
|
"license": "MIT",
|
|
@@ -53,9 +55,14 @@
|
|
|
53
55
|
},
|
|
54
56
|
"dependencies": {
|
|
55
57
|
"dooboolab-welcome": "^1.3.2",
|
|
56
|
-
"react-native-audio-recorder-player":"^3.6.13"
|
|
58
|
+
"react-native-audio-recorder-player": "^3.6.13"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
61
|
+
"@babel/core": "^7.29.7",
|
|
62
|
+
"@babel/preset-env": "^7.29.7",
|
|
63
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
64
|
+
"@types/jest": "^30.0.0",
|
|
65
|
+
"@types/node": "^26.5.0",
|
|
59
66
|
"eslint": "^8.57.0",
|
|
60
67
|
"eslint-config-expo": "^7.1.2",
|
|
61
68
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -68,4 +75,3 @@
|
|
|
68
75
|
"typescript": "^4.9.4"
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
|
-
|