ARCameraContext.startRecord

解释:开始录像

方法参数

Object object

object参数说明

progress 返回参数说明

timeout 返回参数说明

示例

在开发者工具中预览效果

扫码体验

请使用百度APP扫码

图片示例

代码示例

-

  1. <ar-camera ar-key="10298931" ar-type="5" flash="{{flashState}}" class="camera" bindload="loadCameraSuccess" bindmessage="message" binderror="error"> <cover-view s-if="ifRecord" class="cameraState" bindtap="startRecord"> 开始录像 </cover-view> <cover-view s-else class="cameraState" bindtap="stopRecord"> 结束录像 </cover-view> <cover-view> <video src="{{VideoPath}}"></video> </cover-view> <!--重拍,保存的按钮--> <cover-view class="action-complete" s-if="isRecordComplete"> <cover-image class="giveup-img" src="https://b.bdstatic.com/miniapp_cl_ar_back.png" bindtap="reset" /> <cover-image class="save-img" src="https://b.bdstatic.com/miniapp_cl_ar_save.png" bindtap="save" /> </cover-view></ar-camera>

-

  1. Page({ data: { photoSrc: '', ifRecord: true, VideoPath: '', isRecordComplete: false }, onReady() { // 初始化ar相机 this.ARCameraContext = swan.createARCameraContext(); }, startRecord() { let that = this; this.ARCameraContext.startRecord({ success: res => { that.setData({'ifRecord': false}); } }); }, stopRecord() { let that = this; this.ARCameraContext.stopRecord({ success: res => { that.setData({'ifRecord': true}); swan.showModal({ title: 'success', content: JSON.stringify(res) }); that.setData({ VideoPath: res.tempVideoPath, isRecordComplete: true }) } }); }, reset() { this.ARCameraContext.reset({ success: res => { this.setData({ isRecordComplete: false, isUpload: false, photoSrc: '', videoSrc: '' }, () => { this.changeAction(this.data.cameraState); }); }, fail: e => { swan.showToast({ title: JSON.stringify(e), icon: 'none' }); } }); }, save() { swan.saveVideoToPhotosAlbum({ filePath: this.data.VideoSrc, success: handleSaveSuccess.bind(this), fail: handleSaveFail.bind(this) }); function handleSaveSuccess(res) { swan.showToast({ title: '保存成功', success: () => { this.reTake(); } }); this.setData({ isRecordComplete: true, isUpload: false }); } function handleSaveFail(e) { swan.showToast({title: '保存失败'}); } }});