CameraContext.startRecord

2020-08-26 16:25 更新

解释:开始录像

方法参数

Object object

object 参数说明

参数名类型必填默认值说明

timeoutCallback

Function

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

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

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

示例 

在开发者工具中打开


图片示例

代码示例

<view class="wrap">
    <camera
        flash="off" 
        binderror="error" 
        style="width: 100%; height: 500rpx;">
    </camera>
    <button type="primary" bind:tap="startRecord">开始录像</button>
    <button type="primary" bind:tap="stopRecord">结束录像</button>
    <video s-if="videoSrc" class="video" src="{{videoSrc}}"></video>
</view>
Page({
    data: {
        videoSrc: ''
    },
    startRecord() {
        this.cameraContext = swan.createCameraContext();
        this.cameraContext.startRecord({
            success: res => {
                swan.showToast({
                    title: 'startRecord',
                    icon: 'none'
                });
            }
        });
    },
    stopRecord() {
        this.cameraContext.stopRecord({
            success: res => {
                swan.showModal({
                    title: '提示',
                    content: res.tempVideoPath
                });
                this.setData({
                    videoSrc: res.tempVideoPath
                });
            }
        });
    }
});


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

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号