- JS API 列表
- 基础
- 网络
- 媒体
- 地图
- 文件
- 开放接口
- 数据缓存
- 地理位置
- 设备
- 画布
- 界面
- 页面导航
- 侧边栏能力
- 行业开放
- AI/AR能力
- 第三方平台
- TTML
- 转发和挂载
- 其它
- 直播能力
RecorderManager.pause收藏我的收藏
收藏
我的收藏基础库 1.0.0 开始支持本方法,这是一个同步方法。
暂停录音。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
支持沙盒 | 否 |
相关教程 | 无 |
语法
RecorderManager.pause()
参数说明
无
返回值
无
扫码体验
请使用字节宿主APP扫码
代码示例
<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>
</view>
</view>
</view>
const countdown = 6000;
let cdtimer = null;
Page({
data: {
cd: countdown,
isStart: false,
isPlay: false,
options: {
duration: countdown,
sampleRate: 12000,
numberOfChannels: 1,
encodeBitRate: 25000,
frameSize: 100,
}
},
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.recorderManager.onResume(() => {
this.setData({
isPlay: true
});
this.startCountDown();
console.log("已继续录音");
});
// 监听录音停止事件
this.recorderManager.onStop((res) => {
clearInterval(cdtimer);
this.setData({
isStart: false,
isPlay: false,
cd: countdown
});
console.log("已停止录音,录音文件的地址为: ", res.tempFilePath);
});
},
onUnload: function () {
this.stop();
},
start() {
this.recorderManager.start(this.data.options);
},
stop() {
// 停止录音
this.recorderManager.stop();
},
pause() {
// 暂停录音
this.recorderManager.pause();
},
resume() {
// 继续录音
this.recorderManager.resume();
},
startCountDown() {
clearInterval(cdtimer);
cdtimer = setInterval(() => {
this.setData({
cd: this.data.cd - 100
});
}, 100);
}
})
该文档是否有帮助?
点击纠错