- JS API 列表
- 基础
- 网络
- 媒体
- 地图
- 文件
- 开放接口
- 数据缓存
- 地理位置
- 设备
- 画布
- 界面
- 页面导航
- 侧边栏能力
- 行业开放
- AI/AR能力
- 第三方平台
- TTML
- 转发和挂载
- 其它
- 直播能力
EffectCameraStream.offStop收藏我的收藏
收藏
我的收藏语法
Plain Text复制EffectCameraStream.offStop(callback)
参数说明
function callback
回调参数
无
代码示例
预期表现:
- •点击【暂停相机】后出现相机关闭提示弹窗。
- •点击【取消监听相机暂停事件】,再次重复上述操作,不会出现相机关闭提示弹窗。
html复制<canvas type="webgl" id="myCanvas"></canvas>
<button type="primary" bindtap="requestEffectCamera">创建相机</button>
<button type="primary" bindtap="play">打开相机</button>
<button type="primary" bindtap="stop">暂停相机</button>
<button type="primary" bindtap="offStop">取消监听相机暂停事件</button>
js复制Page({
onShow: function (options) {
try {
this.effectCameraStream = tt.createEffectCameraStream(this);
} catch (error) {
console.error("errror", error);
}
this.effectCameraStream.onError(this.onCameraError);
this.effectCameraStream.onRequest(this.onRequest);
this.effectCameraStream.onPlay(this.onPlay);
this.effectCameraStream.onStop(this.onStop);
},
requestEffectCamera() {
tt.createSelectorQuery()
.select("#myCanvas")
.node()
.exec((res) => {
console.log("select query", res);
this.canvas = res[0].node;
this.canvasCtx = this.canvas.getContext("webgl");
this.effectCameraStream.request({
orientation: "back",
});
});
},
onCameraError(error) {
console.log("onError", error);
const { type, errMsg } = error;
tt.showModal({
title: `onError ${type}`,
content: errMsg,
});
},
onRequest() {
console.log("相机资源申请成功");
this.effectCameraStream.play();
},
onPlay(cameraVideo) {
this.cameraStatus = "play";
console.log("相机数据", cameraVideo);
tt.showToast({
title: "相机打开",
});
this.paint();
},
onStop() {
this.cameraStatus = "stop";
tt.showToast({
title: "相机暂停",
});
},
offStop() {
if (this.effectCameraStream) {
this.effectCameraStream.offStop(this.onStop);
}
},
play() {
if (this.effectCameraStream) {
this.effectCameraStream.play();
}
},
stop() {
if (this.effectCameraStream) {
this.effectCameraStream.stop();
}
},
paint() {
this.effectCameraStream.paintTo({
canvas: this.canvasCtx.canvas,
dx: 0,
dy: 0,
sx: 0,
sy: 0,
success: () => {},
fail: (error) => {
console.error("paint fail", error);
},
});
this.requestId = this.canvas.requestAnimationFrame(() => {
this.cameraStatus === "play" && this.paint();
});
},
onHide() {
if (this.effectCameraStream) {
this.canvas.cancelAnimationFrame(this.requestId);
this.effectCameraStream.offRequest(this.onRequest);
this.effectCameraStream.offPlay(this.onPlay);
this.effectCameraStream.offStop(this.offStop);
this.effectCameraStream.offError(this.onCameraError);
this.effectCameraStream.dispose();
this.effectCameraStream = null;
}
},
});
Bug & Tip
暂无。
点击纠错