@react-native-ohos/react-native-audio-recorder-player 3.7.1 → 3.7.3-beta.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.
- package/CHANGELOG.md +25 -0
- package/README.md +83 -6
- 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 +37 -31
- package/harmony/audio_recorder_player/src/main/ets/audioPlayer/AudioPlayer.ts +29 -23
- package/harmony/audio_recorder_player/src/main/ets/recorder/Recorder.ts +10 -4
- package/harmony/audio_recorder_player/src/main/ets/utils/SaveAudioAsset.ts +4 -8
- package/harmony/audio_recorder_player.har +0 -0
- package/index.ts +2 -2
- package/package.json +18 -7
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 鸿蒙化Log
|
|
4
|
+
- fix: fix multiple-instance and repeated-click issues, bump version to 3.7.3-beta.1 [#51](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/51)
|
|
5
|
+
|
|
6
|
+
### v3.7.3-beta.1
|
|
7
|
+
|
|
8
|
+
### v3.7.2
|
|
9
|
+
- 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)
|
|
10
|
+
- 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)
|
|
11
|
+
- fix: modify quality hardening bug for master update [#47](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/47)
|
|
12
|
+
|
|
13
|
+
### v3.7.1
|
|
14
|
+
- release version v3.7.1 [#39](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/39)
|
|
15
|
+
- docs: update readme [#36](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/36)
|
|
16
|
+
- docs: 更新82 react-native-audio-recorder-player中英文文档 [#33](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/33)
|
|
17
|
+
- feat: 82适配以及支持autolink [#27](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/27)
|
|
18
|
+
- merge:同步77分支代码到master分支 [#25](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/25)
|
|
19
|
+
- merge:同步77分支代码到master分支 [#26](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/26)
|
|
20
|
+
- docs: 更新readme [#28](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/28)
|
|
21
|
+
- fix:把遗漏的封装格式AAC补齐 [#22](https://gitcode.com/CPF-RN/rntpc_react-native-audio-recorder-player/pull/22)
|
|
22
|
+
|
|
23
|
+
### v3.7.0
|
|
24
|
+
- 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)
|
|
25
|
+
|
package/README.md
CHANGED
|
@@ -192,7 +192,7 @@ ohpm install
|
|
|
192
192
|
|
|
193
193
|
#### 在 entry 目录下的module.json5中添加权限
|
|
194
194
|
|
|
195
|
-
在`entry/src/main/module.json5
|
|
195
|
+
在`entry/src/main/module.json5`中添加:
|
|
196
196
|
|
|
197
197
|
```json
|
|
198
198
|
"requestPermissions": [
|
|
@@ -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` | 将毫秒转换为“分:秒”格式的字符串 | function(
|
|
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.1';
|
|
4
|
+
export const HAR_VERSION = '3.7.3-beta.1';
|
|
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.1",
|
|
8
|
+
"version": "3.7.3-beta.1",
|
|
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
|
},
|
|
@@ -26,7 +26,7 @@ import { AnyThreadTurboModule, AnyThreadTurboModuleContext } from '@rnoh/react-n
|
|
|
26
26
|
import { media } from '@kit.MediaKit';
|
|
27
27
|
import type { AudioSet } from '.';
|
|
28
28
|
import Recorder from './recorder/Recorder';
|
|
29
|
-
import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, } from './recorder/types';
|
|
29
|
+
import { AVRecorderState, defaultBitrate, defaultChannels, defaultSampleRate, RecordBackName, processValue as recorderProcessValue } from './recorder/types';
|
|
30
30
|
import AudioPlayer from './audioPlayer/AudioPlayer';
|
|
31
31
|
import { AVPlayerState, EventTarget, playBackName, processValue, } from './audioPlayer/types';
|
|
32
32
|
import deviceinfo from '@ohos.deviceInfo';
|
|
@@ -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
|
/**
|
|
@@ -150,7 +152,11 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
150
152
|
meteringEnabled?: boolean,
|
|
151
153
|
): Promise<string> {
|
|
152
154
|
if (this.isRecording()) {
|
|
153
|
-
return Promise.reject(
|
|
155
|
+
return Promise.reject(recorderProcessValue.start);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!!!uri) {
|
|
159
|
+
return Promise.reject('empty uri');
|
|
154
160
|
}
|
|
155
161
|
this.meteringEnabled = meteringEnabled === true ? true : false;
|
|
156
162
|
const profile: media.AVRecorderProfile = this.getAudioSets(audioSets);
|
|
@@ -189,7 +195,7 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
189
195
|
this.removeRecordBackListener();
|
|
190
196
|
return this.AVRecorderInstance.pauseRecordingProcess();
|
|
191
197
|
}
|
|
192
|
-
return Promise.reject(
|
|
198
|
+
return Promise.reject(recorderProcessValue.stateError);
|
|
193
199
|
}
|
|
194
200
|
|
|
195
201
|
/**
|
|
@@ -201,7 +207,7 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
201
207
|
this.addRecordBackListener();
|
|
202
208
|
return this.AVRecorderInstance.resumeRecordingProcess();
|
|
203
209
|
}
|
|
204
|
-
return Promise.reject(
|
|
210
|
+
return Promise.reject(recorderProcessValue.stateError);
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
/**
|
|
@@ -218,9 +224,14 @@ export class RNAudioRecorderPlayerTurboModule extends AnyThreadTurboModule {
|
|
|
218
224
|
this.removeRecordBackListener();
|
|
219
225
|
return this.AVRecorderInstance.stopRecordingProcess();
|
|
220
226
|
}
|
|
221
|
-
return Promise.reject(
|
|
227
|
+
return Promise.reject(recorderProcessValue.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;
|
|
@@ -121,7 +127,7 @@ export default class Player {
|
|
|
121
127
|
// start button process
|
|
122
128
|
async startPlayeringProcess(url?: string, httpHeaders?: Record<string, string>): Promise<string> {
|
|
123
129
|
Logger.debug(TAG, 'startPlayering called');
|
|
124
|
-
if (this.isPlaying || this.PlayerState === AVPlayerState.paused) {
|
|
130
|
+
if (this.isPlaying || this.PlayerState === AVPlayerState.paused || this.PlayerState === AVPlayerState.initialized) {
|
|
125
131
|
return;
|
|
126
132
|
}
|
|
127
133
|
try {
|
|
@@ -131,7 +137,7 @@ export default class Player {
|
|
|
131
137
|
return this.playUrl;
|
|
132
138
|
} catch (err) {
|
|
133
139
|
Logger.error(TAG, `startPlayering fail code:${(err as BusinessError).code}`);
|
|
134
|
-
this.stopPlayeringProcess();
|
|
140
|
+
await this.stopPlayeringProcess();
|
|
135
141
|
return this.playUrl;
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -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;
|
|
@@ -167,8 +172,8 @@ export default class Player {
|
|
|
167
172
|
// stop button process
|
|
168
173
|
async stopPlayeringProcess(): Promise<string> {
|
|
169
174
|
Logger.debug(TAG, 'stopPlayering called');
|
|
170
|
-
if (!this.
|
|
171
|
-
return processValue.
|
|
175
|
+
if (!this.audioPlayer) {
|
|
176
|
+
return processValue.stop;
|
|
172
177
|
}
|
|
173
178
|
this.isPlaying = false;
|
|
174
179
|
this.currentPosition = 0;
|
|
@@ -249,13 +254,13 @@ export default class Player {
|
|
|
249
254
|
|
|
250
255
|
private async createAudioPlayer(): Promise<void> {
|
|
251
256
|
if (this.audioPlayer) {
|
|
252
|
-
this.stopPlayeringProcess();
|
|
257
|
+
await this.stopPlayeringProcess();
|
|
253
258
|
}
|
|
254
259
|
await media
|
|
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!!!');
|
|
@@ -290,9 +295,11 @@ export default class Player {
|
|
|
290
295
|
break;
|
|
291
296
|
}
|
|
292
297
|
case AVPlayerState.initialized: {
|
|
298
|
+
this.PlayerState = AVPlayerState.initialized;
|
|
293
299
|
this.getDurationTime();
|
|
294
300
|
this.prepareAudioPlayer();
|
|
295
301
|
this.getCurrentPosition();
|
|
302
|
+
break;
|
|
296
303
|
}
|
|
297
304
|
case AVPlayerState.prepared: {
|
|
298
305
|
this.PlayerState = AVPlayerState.prepared;
|
|
@@ -317,7 +324,7 @@ export default class Player {
|
|
|
317
324
|
case AVPlayerState.completed: {
|
|
318
325
|
this.isPlaying = false;
|
|
319
326
|
this.audioPlayer.off(EventTarget.timeUpdate);
|
|
320
|
-
//
|
|
327
|
+
// completed 执行完成后执行stopped
|
|
321
328
|
}
|
|
322
329
|
case AVPlayerState.stopped: {
|
|
323
330
|
this.PlayerState = AVPlayerState.stopped;
|
|
@@ -367,6 +374,7 @@ export default class Player {
|
|
|
367
374
|
this.audioPlayer.url = fdPath + lastUrl;
|
|
368
375
|
return;
|
|
369
376
|
}
|
|
377
|
+
this.playUrl = ''; // 清空无效地址
|
|
370
378
|
Logger.error(TAG, 'this uri is not allowed');
|
|
371
379
|
return Promise.reject('this uri is not allowed');
|
|
372
380
|
}
|
|
@@ -392,20 +400,14 @@ export default class Player {
|
|
|
392
400
|
isExist = fs.accessSync(`${path}/${'sound.m4a'}`);
|
|
393
401
|
}
|
|
394
402
|
if (isExist) {
|
|
395
|
-
|
|
403
|
+
if (url && url === 'DEFAULT') {
|
|
404
|
+
this.playUrl = `${path}/${'sound.m4a'}`;
|
|
405
|
+
} else {
|
|
406
|
+
this.playUrl = `${path}/${url}`;
|
|
407
|
+
}
|
|
396
408
|
const file = fs.openSync(this.playUrl);
|
|
397
409
|
return file.fd;
|
|
398
410
|
} 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
411
|
return null;
|
|
410
412
|
}
|
|
411
413
|
}
|
|
@@ -459,6 +461,10 @@ export default class Player {
|
|
|
459
461
|
}, this.failureCallback)
|
|
460
462
|
.catch(this.catchCallback);
|
|
461
463
|
this.audioPlayer = undefined;
|
|
464
|
+
|
|
465
|
+
if (this.EventMap) {
|
|
466
|
+
this.EventMap.clear()
|
|
467
|
+
}
|
|
462
468
|
}
|
|
463
469
|
}
|
|
464
470
|
}
|
|
@@ -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,
|
|
@@ -244,8 +250,8 @@ export default class Recorder {
|
|
|
244
250
|
private async prepareAudioRecorder(): Promise<void> {
|
|
245
251
|
Logger.debug(TAG, 'case prepareAudioRecorder in');
|
|
246
252
|
await this.audioRecorder!.prepare(this.avConfig)
|
|
247
|
-
.then(() => {
|
|
248
|
-
this.audioRecorder!.start();
|
|
253
|
+
.then(async() => {
|
|
254
|
+
await this.audioRecorder!.start();
|
|
249
255
|
Logger.debug(TAG, 'case prepare AVRecorder called');
|
|
250
256
|
}, this.catchCallback)
|
|
251
257
|
.catch(this.catchCallback);
|
|
@@ -264,7 +270,7 @@ export default class Recorder {
|
|
|
264
270
|
if (this.audioRecorder) {
|
|
265
271
|
await this.audioRecorder.off(AVRecorderState.onStateChange);
|
|
266
272
|
await this.audioRecorder.off(AVRecorderState.error);
|
|
267
|
-
this.audioRecorder
|
|
273
|
+
await this.audioRecorder
|
|
268
274
|
.release()
|
|
269
275
|
.then(() => {
|
|
270
276
|
this.audioRecorder = undefined;
|
|
@@ -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/index.ts
CHANGED
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.1",
|
|
3
|
+
"version": "3.7.3-beta.1",
|
|
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"
|
|
@@ -36,14 +37,20 @@
|
|
|
36
37
|
"record",
|
|
37
38
|
"recorder",
|
|
38
39
|
"player",
|
|
39
|
-
"harmony"
|
|
40
|
+
"harmony",
|
|
41
|
+
"harmonyos",
|
|
42
|
+
"ohos",
|
|
43
|
+
"openharmony",
|
|
44
|
+
"rnoh"
|
|
40
45
|
],
|
|
41
46
|
"files": [
|
|
42
47
|
"src",
|
|
43
48
|
"harmony",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"!build"
|
|
49
|
+
"index.ts",
|
|
50
|
+
"index.d.ts",
|
|
51
|
+
"!build",
|
|
52
|
+
"README.md",
|
|
53
|
+
"CHANGELOG.md"
|
|
47
54
|
],
|
|
48
55
|
"author": "dooboolab",
|
|
49
56
|
"license": "MIT",
|
|
@@ -53,9 +60,14 @@
|
|
|
53
60
|
},
|
|
54
61
|
"dependencies": {
|
|
55
62
|
"dooboolab-welcome": "^1.3.2",
|
|
56
|
-
"react-native-audio-recorder-player":"^3.6.13"
|
|
63
|
+
"react-native-audio-recorder-player": "^3.6.13"
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
66
|
+
"@babel/core": "^7.29.7",
|
|
67
|
+
"@babel/preset-env": "^7.29.7",
|
|
68
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
69
|
+
"@types/jest": "^30.0.0",
|
|
70
|
+
"@types/node": "^26.5.0",
|
|
59
71
|
"eslint": "^8.57.0",
|
|
60
72
|
"eslint-config-expo": "^7.1.2",
|
|
61
73
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -68,4 +80,3 @@
|
|
|
68
80
|
"typescript": "^4.9.4"
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
|
-
|