onRecordingEvent(listener: Function)
版本要求:
BaseKit≥2.3.2@ray-js/ray≥0.3.23
支持平台:
iOSAndroid
import { onRecordingEvent } from '@ray-js/ray';
// Promise 调用
try {
const res = await onRecordingEvent({ ...params });
console.log(res);
} catch (err) {
console.log(err.errorMsg);
}描述
持续录音事件
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| 是 |
返回值
无
示例代码
import { getRecorderManager, onRecordingEvent } from '@ray-js/ray'
const manager = await getRecorderManager();
let stopped = false;
onRecordingEvent(e => {
console.log(e);
// 收到首个录音数据事件后即停止,事件已触发且自清理。
if (!stopped) {
stopped = true;
manager.stopRecording({ success: () => {}, fail: () => {} });
}
});
// 开始持续录音以产生 onRecordingEvent 数据回调。
manager.startRecording({
period: 200,
pcm16IOS: true,
success: data => {
console.log(data);
},
fail: error => {
console.error(error);
},
});