RecorderManager.onStop
基础库 1.0.0 开始支持本方法,这是一个同步方法。
监听录音结束事件,成功时回调录音文件临时路径。
语法
RecorderManager.onStop(callback)
参数说明
callback
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
function | 是 | 回调函数 | 1.0.0 |
回调函数参数说明
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
tempFilePath | number | 录音文件临时地址 | 1.0.0 |
duration | number | 录音时长 | 1.0.0 |
fileSize | number | 录音文件大小 | 1.0.0 |
返回值
无
扫码体验
请使用字节宿主APP扫码
代码示例
<!-- index.ttml -->
<button type="primary" bindtap="startRecord">开始录音</button>
<button type="primary" bindtap="stopRecord">停止录音</button>
<view>录音状态:{{status}}</view>
// index.js
Page({
data: {
status: "暂未开始",
},
startRecord() {
this.recorderManager = tt.getRecorderManager();
const options = {
duration: 60000,
sampleRate: 12000,
numberOfChannels: 1,
encodeBitRate: 25000,
frameSize: 100,
};
this.recorderManager.onStop((res) => {
tt.showModal({
title: "录音结束",
content: JSON.stringify(res),
});
this.setData({
status: "录音结束",
});
});
this.recorderManager.start(options);
tt.showToast({ title: "点击了开始录音" });
this.setData({
status: "正在录音",
});
},
stopRecord() {
this.recorderManager && this.recorderManager.stop();
},
});
Bug & Tip
无
点击纠错
该文档是否对你的开发有所帮助?
有帮助
没帮助
该文档是否对你的开发有所帮助?
有帮助
没帮助