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