ARCameraContext.startRecord

2020-08-26 16:25 更新

解釋:開始錄像

方法參數(shù)

Object object

object參數(shù)說明

參數(shù)類型必填默認(rèn)值說明

progress

Function

錄制進(jìn)度更新的回調(diào)函數(shù)。

timeout

Function

超過 10s 或頁(yè)面 onHide 時(shí)會(huì)結(jié)束錄像。

success

Function

接口調(diào)用成功的回調(diào)函數(shù)

fail

Function

接口調(diào)用失敗的回調(diào)函數(shù)

complete

Function

接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)

progress 返回參數(shù)說明

參數(shù)名類型說明

progress

String

視頻的臨時(shí)路徑

timeout 返回參數(shù)說明

參數(shù)名類型說明

tempVideoPath

String

視頻的臨時(shí)路徑

示例 

在開發(fā)者工具中打開


圖片示例

代碼示例


<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">結(jié)束錄像</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相機(jī)
        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: '保存失敗'});
        }
    }
});


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)