EffectCameraStream.onStop收藏我的收藏
收藏
我的收藏语法
EffectCameraStream.onStop(callback)
参数说明
function callback
回调参数
无
代码示例
预期表现:
- •依次点击【打开相机】-> 【关闭相机】出现相机关闭弹窗提示。
- •打开相机后点击【释放相机资源】,再次重复上述步骤,出现相机关闭弹窗提示。
<button type="primary" bindtap="requestEffectCamera">打开相机</button> <button type="primary" bindtap="stopEffectCamera">关闭相机</button> <button type="primary" bindtap="disposeEffectCamera">释放相机资源</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); this.effectCameraStream.onStop(this.onStop); }, requestEffectCamera() { this.effectCameraStream.request({ orientation: "front", }); }, stopEffectCamera() { if (this.effectCameraStream) { this.effectCameraStream.stop(); } }, disposeEffectCamera() { if (this.effectCameraStream) { this.effectCameraStream.dispose(); this.effectCameraStream = null; tt.showToast({ title: "相机资源释放", }); } }, 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); }, onStop() { tt.showToast({ title: "相机关闭", }); }, });
Bug & Tip
暂无。