MediaRecorder.onStop
收藏
我的收藏

基础库 2.52.0 开始支持本方法,低版本需做兼容处理,这是一个同步方法。​
监听录制结束事件。​

语法​

Plain Text
复制
MediaRecorder.onStop(callback)

参数说明​

callback​

类型
默认值
必填
说明
最低支持版本
function
录制结束后要执行的回调函数
2.52.0

回调函数参数说明​

属性名
类型
说明
filePath
string
视频文件的路径
duration
number
视频文件的时长(单位为秒)
fileSize
number
视频文件的大小(单位为 kb)

返回值​

无​

扫码体验​

代码示例​

html
复制
<canvas id="myCanvas" canvas-id="myCanvas" type="2d"> </canvas>
<button type="primary" bindtap="stop">结束录制</button>
js
复制
Page({
async onReady() {
tt.createSelectorQuery()
.select("#myCanvas")
.node()
.exec((res) => {
// 获取 canvas 实例
const canvas = res[0].node;
const canvasCtx = canvas.getContext("2d");
this.recorder = tt.createMediaRecorder(canvas, {
width: canvas.width, // video width
height: canvas.height, // video height
videoBitsPerSecond: 1000, // bit rate in kbps
gop: 12, // key frame interval
fps: 60, // frames per second
});
this.recorder.onStop((stop_info) => {
console.log("stop_info: ", stop_info);
});
});
},
stop() {
this.recorder.stop();
tt.showToast({
title: "stop",
icon: "none",
});
},
});

Bug & Tip​

无​