ARCameraContext.startRecord

2020-08-26 16:25 更新

解释:开始录像

方法参数

Object object

object参数说明

参数类型必填默认值说明

progress

Function

否

录制进度更新的回调函数。

timeout

Function

否

超过 10s 或页面 onHide 时会结束录像。

success

Function

否

接口调用成功的回调函数

fail

Function

否

接口调用失败的回调函数

complete

Function

否

接口调用结束的回调函数(调用成功、失败都会执行)

progress 返回参数说明

参数名类型说明

progress

String

视频的临时路径

timeout 返回参数说明

参数名类型说明

tempVideoPath

String

视频的临时路径

示例 

在开发者工具中打开


图片示例

代码示例


<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" rel="external nofollow"  bindtap="reset" />
        <cover-image class="save-img" src="https://b.bdstatic.com/miniapp_cl_ar_save.png" rel="external nofollow"  bindtap="save" />
    </cover-view>

</ar-camera>
Page({
    data: {
        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,
                    VideoPath: ''
                });
            },
            fail: e => {
                swan.showToast({
                    title: JSON.stringify(e),
                    icon: 'none'
                });
            }
        });
    },
    save() {
        swan.saveVideoToPhotosAlbum({
            filePath: this.data.VideoPath,
            success: handleSaveSuccess.bind(this),
            fail: handleSaveFail.bind(this)
        });


        function handleSaveSuccess(res) {
            swan.showToast({
                title: '保存成功'
            });

            this.setData({
                isRecordComplete: true
            });
        }

        function handleSaveFail(e) {
            swan.showToast({title: '保存失败'});
        }
    }
});


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号