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

RecorderManager.offResume

收藏
我的收藏

基础库 1.0.0 开始支持本方法,这是一个同步方法。

取消监听 RecorderManager.onResume 中绑定的事件处理函数。

前提条件
业务背景
使用限制
注意事项
支持沙盒
相关教程

语法

RecorderManager.offResume(callback)

参数说明

callback

类型默认值必填说明最低支持版本
function
RecorderManager.onResume 中绑定的事件处理函数;如果没有传递,则解绑所有的事件处理函数
1.0.0

返回值

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

<!-- index.ttml --> <view class="container"> <view class="body"> <text class="text-space">剩余录音时间 {{ cd }}ms</text> <view class="btn-area"> <button type="primary" bindtap="start" disabled="{{ isStart }}"> start </button> <button type="primary" bindtap="pause" tt:if="{{ isPlay }}">pause</button> <button type="primary" bindtap="resume" tt:if="{{ !isPlay }}" disabled="{{ !isStart }}" > resume </button> <button type="primary" bindtap="stop" disabled="{{ !isStart }}"> stop </button> <button type="primary" bindtap="offResume">offResume</button> </view> </view> </view>
// index.js const countDown = 60000; let cdTimer = null; Page({ data: { cd: countDown, isStart: false, isPlay: false, options: { duration: countDown, sampleRate: 12000, numberOfChannels: 1, encodeBitRate: 25000, frameSize: 100, }, }, /** onResume的事件处理函数 */ onResumeCallback: null, onLoad() { this.recorderManager = tt.getRecorderManager(); // 监听录音开始事件 this.recorderManager.onStart(() => { this.setData({ isStart: true, isPlay: true, cd: countDown, }); this.startCountDown(); }); // 监听录音暂停事件 this.recorderManager.onPause(() => { this.setData({ isPlay: false, }); clearInterval(cdTimer); console.log("已暂停录音"); }); // 监听录音继续事件 this.onResumeCallback = () => { this.setData( { isPlay: true, }, () => { this.startCountDown(); tt.showToast({ title: "onResume", icon: "none", }); } ); }; this.recorderManager.onResume(this.onResumeCallback); // 监听录音停止事件 this.recorderManager.onStop((res) => { clearInterval(cdTimer); this.setData({ isStart: false, isPlay: false, cd: countDown, }); console.log("已停止录音,录音文件的地址为: ", res.tempFilePath); }); }, onUnload: function () { this.stop(); }, start() { tt.getSetting({ success: (res) => { let recordAllowed = res.authSetting["scope.record"]; if (!recordAllowed) { tt.showToast({ title: "请授权录音后重新进入" }); } else { // 开始录音 this.recorderManager.start(this.data.options); console.log("已开始录音"); } }, }); }, stop() { // 停止录音 this.recorderManager.stop(); }, pause() { // 暂停录音 this.recorderManager.pause(); }, resume() { // 继续录音 this.recorderManager.resume(); }, offResume() { // this.onResumeCallback if (this.onResumeCallback) { this.recorderManager.offResume(this.onResumeCallback); this.onResumeCallback = null; tt.showToast({ title: "offResume", icon: "none", }); } }, startCountDown() { clearInterval(cdTimer); cdTimer = setInterval(() => { this.setData({ cd: this.data.cd - 100, }); }, 100); }, });