完整的代码如下:
wxml
<view class="container">
<camera device-position="back" flash="off" class="camera"></camera>
<view class="btngroup">
<button bindtap="startRecording">开始录制</button>
<button bindtap="stopRecording">停止录制</button>
</view>
<video wx:if="{{videoSrc}}" src="{{videoSrc}}" controls></video>
</view>jsPage({
data: {
videoSrc: '',
isRecording: false
},
onLoad: function() {
},
startRecording: function() {
const that = this;
const cameraContext = wx.createCameraContext();
cameraContext.startRecord({
success: (res) => {
console.log('开始录制视频');
that.setData({
isRecording: true
});
},
fail: (error) => {
console.error('开始录制失败:', error);
wx.showToast({
title: '开始录制失败',
icon: 'none'
});
}
});
},
stopRecording: function() {
const that = this;
const cameraContext = wx.createCameraContext();
cameraContext.stopRecord({
success: (res) => {
console.log('录制视频成功');
that.setData({
isRecording: false,
videoSrc: res.tempVideoPath
});
that.saveVideo(res.tempVideoPath);
},
fail: (error) => {
console.error('停止录制失败:', error);
wx.showToast({
title: '停止录制失败',
icon: 'none'
});
}
});
},
saveVideo: function(videoPath) {
const that = this;
wx.showLoading({
title: '正在处理视频',
});
wx.saveVideoToPhotosAlbum({
filePath: videoPath,
success: function(res) {
wx.hideLoading();
wx.showToast({
title: '视频已保存',
icon: 'success'
});
},
fail: function(error) {
wx.hideLoading();
console.error('保存视频失败:', error);
wx.showToast({
title: '保存视频失败',
icon: 'none'
});
}
});
}
});wxss.container {
position: relative;
width: 100%;
height: 100vh;
}
.camera {
width: 100%;
height: 100%;
}
.btngroup {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
} 网友回复
linux stream如何限制单个目录最大容量?
哪有免费的千问qwen3.6-plus的api可以使用?
python如何自动根据视频图片等素材自动按照要求剪辑视频生成剪映草稿?
gemma4与开源的qwen3.5哪个更厉害?
wan2.7 video与seedance2哪个更好?
claude code 51万行代码泄露被迫开源在哪能找到源码?
有没有免费的虚拟局域网工具可以将互联网设备组成一个大的局域网?
全球顶尖大模型这么强,为啥AGI 测试集体溃败 人类满分 AI 最高仅 0.37%?
听说字节seedance3的视频生成长度可达到10分钟?
谷歌的TurboQuant是不是真的?


