抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台

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(); }, });