Camera.resume收藏我的收藏
收藏
我的收藏恢复摄像头画面,这是个同步 API。
语法
Camera.resume()
参数说明
无。
代码示例
console.log("开发字节跳动小游戏过程中可以参考以下文档:");
console.log("https://developer.toutiao.com/docs/game/");
const canvas = tt.createCanvas();
const ctx = canvas.getContext("2d");
const camera = tt.createCamera();
console.log("camera", camera);
camera.setBeautifyParam(0.8, 0.79, 0.4, 0.58);
camera
.start("front", true, { matting: true })
.then((video) => {
draw(video);
})
.catch((err) => {
tt.showToast({
title: "相机需要授权",
});
console.log(err);
});
// 3s 后暂停摄像头视频画面
setTimeout(() => {
camera.pause();
}, 3000);
// 6s 后恢复摄像头画面
setTimeout(() => {
camera.resume();
}, 6000);
function draw(video) {
let scale = video.videoHeight / video.videoWidth;
video &&
ctx.drawImage(
video,
0,
0,
video.videoWidth,
video.videoHeight,
0,
0,
canvas.width,
canvas.width * scale,
);
requestAnimationFrame(function () {
draw(video);
});
}
Bug & Tip
- Tip:开发者工具暂不支持此能力,请用真机扫码调试。