EffectCameraStream.play
收藏
我的收藏

基础库 2.19.0 开始支持本方法,低版本需做兼容处理,这是一个同步方法。​
开启相机,通过 EffectCameraStream.onPlay 可监听该请求成功事件,成功后返回相机数据 EffectCameraVideo 实例。通过 EffectCameraStream.onError 可监听该请求失败事件。​

语法​

EffectCameraStream.play()

参数说明​

无​

返回值​

无​

代码示例​

预期表现:点击按钮后弹出相机授权弹窗(如果未曾授权),授权后相机开启,并出现弹窗提示“相机打开”。​
<button type="primary" bindtap="requestEffectCamera">打开相机</button>
Page({ onShow: function (options) { this.effectCameraStream = tt.createEffectCameraStream(this); this.effectCameraStream.onError(this.onError); this.effectCameraStream.onRequest(this.onRequest); this.effectCameraStream.onPlay(this.onPlay); }, requestEffectCamera() { this.effectCameraStream.request({ orientation: "front", }); }, onError(error) { console.log("onError", error); const { type, errMsg } = error; tt.showModal({ title: `onError ${type}`, content: errMsg, }); }, onRequest() { console.log("相机资源申请成功"); this.effectCameraStream.play(); }, onPlay(cameraVideo) { tt.showToast({ title: "相机打开", // 内容 }); console.log("相机数据", cameraVideo); }, });

Bug & Tip​

暂无。​