EffectCameraStream.onError
收藏
我的收藏

基础库 2.9.0 开始支持本方法,低版本需做兼容处理。​
监听 EffectCameraStream 生命周期中的业务错误,包括:request, play, stop。可通过 EffectCameraStream.offError 取消监听。​

语法​

Plain Text
复制
EffectCameraStream.onError(callback)

参数说明​

function callback​

回调参数​

Object object​
属性名
类型
说明
type
string
生命周期事件类型,如 'request', 'play', 'stop'
errMsg
string
错误信息

代码示例​

预期表现:连续点击【打开相机】,弹出错误提示。​
html
复制
<button type="primary" bindtap="requestEffectCamera">打开相机</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,
});
},
onRequest() {
tt.showModal({
title: "相机资源申请成功",
});
},
});

Bug & Tip​

暂无。​