RecorderManager.offStop
基础库 1.0.0 开始支持本方法,这是一个同步方法。
取消监听录音结束事件。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
支持沙盒 | 否 |
相关教程 | 无 |
语法
RecorderManager.offStop(callback)
参数说明
callback
类型 | 默认值 | 必填 | 说明 | 最低支持 版本 |
---|---|---|---|---|
function | 否 | 取消监听录音结束事件的回调。没有 callback 则取消所有的监听录音结束事件的回调,有 callback 则只取消对应的监听回调 | 1.0.0 |
返回值
无
扫码体验
请使用字节宿主APP扫码
代码示例
<button type="primary" bindtap="startRecord">开始录音</button> <button type="primary" bindtap="stopRecord">停止录音</button> <view>录音状态:{{status}}</view>
Page({ data: { status: "暂未开始", }, // onStop时绑定的事件处理函数 onStopCallback: null, onUnload() { this.recorderManager && this.recorderManager.offStop(); this.onStopCallback = null; }, startRecord() { this.recorderManager = tt.getRecorderManager(); const options = { duration: 60000, sampleRate: 12000, numberOfChannels: 1, encodeBitRate: 25000, frameSize: 100, }; // 如果目前没有绑定onStop的事件处理函数才能够绑定 if (!onStopCallback) { this.onStopCallback = (res) => { tt.showModal({ title: "录音结束", content: JSON.stringify(res), }); this.setData({ status: "录音结束", }); }; this.recorderManager.onStop(this.onStopCallback); } this.recorderManager.start(options); tt.showToast({ title: "点击了开始录音" }); this.setData({ status: "正在录音", }); }, stopRecord() { this.recorderManager && this.recorderManager.stop(); }, });