完整的代码如下:
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>js
Page({ 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%); }
网友回复
python如何在电脑上通过局域网将本地视频或m3u8视频投屏电视播放?
腾讯视频爱奇艺优酷vip电影电视剧视频如何通过python绕过vip收费直接观看?
有没有可免费观看全球电视台直播m3u8地址url的合集?
有没有实现观影自由的免vip影视苹果 CMS V10 API的可用url?
python如何实时检测电脑usb插入检测报警?
如何判断真人操作的鼠标移动直线轨迹与机器操作的轨迹?
人形机器人的运动能否有端侧ai全面接管?
有没有抓取抖音头条等自媒体平台指定主题的评论的python开源程序?
css如何实现多个代码块向下滚动右上角复制按钮sticky粘性在顶部效果?
python+Quill如何实现多人实时文档编辑html?