wxml
<view class="title">相机管理</view>
<view class="demo-box">
<view class="title">录像功能应用</view>
<camera device-position="back" flash="off" style="width: 100%; height: 300px;"></camera>
<button wx:if="{{isRecording}}" type="primary" bindtap="stopRecord">结束录像</button>
<button wx:else type="primary" bindtap="startRecord">开始录像</button>
<video hidden="{{isHidden}}" src="{{src}}" controls></video>
</view>
js
Page({
data: {
isRecording:false,
isHidden:true
},
startRecord:function(){
var that=this
that.setData({isRecording:true,isHidden:true})
this.ctx.startRecord({
//超时自动结束
timeoutCallback(res){
that.setData({
isRecording:false,
src:res.tempVideoPath,//更新视频路径
isHidden:false//显示video组件
})
}
})
},
//停止录像
stopRecord:function(){
var that=this
this.ctx.stopRecord({
success:function(res){
that.setData({
isRecording:false,
src:res.tempVideoPath,
isHidden:false
})
}
})
},
onLoad:function(options){
this.ctx=wx.createCameraContext()
},
}