EffectCameraStream.offError
收藏
我的收藏

基础库 2.19.0 开始支持本方法,低版本需做兼容处理。​
取消对 EffectCameraStream 生命周期错误事件的监听,包括:request, play, stop。取消后 EffectCameraStream.onError 将不触发。​

语法​

Plain Text
复制
EffectCameraStream.offError(callback)

参数说明​

function callback​

回调参数​

无​

代码示例​

预期表现:连续点击【打开相机】,弹出错误提示。​
点击【取消错误监听】后,再次重复点击【打开相机】,不出现错误提示。​
html
复制
<button type="primary" bindtap="requestEffectCamera">打开相机</button>
<button type="primary" bindtap="offError">取消错误监听</button>
js
复制
Page({
onShow: function (options) {
this.effectCameraStream = tt.createEffectCameraStream(this);
this.effectCameraStream.onError(this.onError);
this.effectCameraStream.onRequest(this.onRequest);
},
requestEffectCamera() {
this.effectCameraStream.request({
orientation: "front",
});
},
onError(error) {
console.log("onError", error);
const { type, errMsg } = error;
tt.showModal({
title: `onError ${type}`,
content: errMsg,
});
},
offError() {
tt.showToast({
title: "取消错误监听",
});
this.effectCameraStream.offError(this.onError);
},
onRequest() {
tt.showModal({
title: "相机资源申请成功",
});
},
});

Bug & Tip​

暂无。​