uniapp开发微信小程序对接萤石云,实现监控预览(云台控制、截图)监控回放功能

效果图:

前言:

根据萤石云官网,我采用的是插件的形式

萤石云官网中有详细的方法教程:文档概述 · 萤石开放平台API文档 

监控预览:

 ezplayer中 我用到的参数配置就这几个,官网有非常详细的解释,这里就不说了

<view class="video_demo" v-if="ezstate" id="video_demo">
				<ezplayer id="ezplayer" :accessToken="accessToken" :url="ezplayerUrl" plugins="talk,capture,ptz"
					bind:handleError="handleError" />
</view>

监控预览其实非常简单,配对这两个参数传过去就ok了,如果像我这样有多个摄像头在同一页面切换的情况,可能会出现切换了设备,但是监控视频还是上一个的情况,这时候用v-if重新渲染即可。

监控回放:

监控回放也不难,但是官网文档没有教程 。 开始时间直接就是00:00:00就行,结束时间写23:59:59,占位即可,自带的插件会自己补时间。

第一步:

用的是uniapp自带的一个切换组件和选择日期组件

<uni-segmented-control :current="currentSeg" :values="itemSeg" :style-type="styleType" :active-color="activeColor"
				@clickItem="onClickItem" />

<view v-if="currentSeg === 1" style="padding: 0 20rpx; padding-bottom: 20rpx;">
			<uni-datetime-picker type="date" :clear-icon="false" v-model="singDate" @change="changeDate" />
		</view>
// 获取当前日期
onDateFn() {
				const today = new Date();
				const year = today.getFullYear();
				const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以需要加1
				const day = String(today.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				this.singDate = formattedDate
			},
// 选择日期 
changeDate(e) {
                // this.ezplayerUrl 是传给萤石云插件的url
				let startIndex = this.ezplayerUrl.indexOf("local");
				let result = this.ezplayerUrl.substring(0, startIndex + "local".length);
				this.ezplayerUrl = `${result}${e} 00:00:00/${e} 23:59:59`
			},
// 预览回放切换
onClickItem(e) {
				this.currentSeg = e.currentIndex
				this.ezstate = false
				if (this.currentSeg === 0) {
					this.typeE = 'live'
					this.ezplayerUrl = this.ezplayerUrl.replace('local', 'live');
				} else if (this.currentSeg === 1) {
					this.typeE = 'local'
					const ezUrl = this.ezplayerUrl.replace('live', 'local');
					this.ezplayerUrl = `${ezUrl}/${this.singDate} 00:00:00/${this.singDate} 23:59:59`
				}
				setTimeout(() => {
					this.ezstate = true
				}, 500);

			},

### UniApp实现云台设备监控的方法 在 UniApp 开发环境中,为了实现云台设备的有效监控,通常会借助第三方平台的服务接口来完成特定功能。对于萤石服务而言,在创建组件之后,需通过调用其提供的 API 来获取视频流并操作云台。 #### 初始化项目配置 首先确保已经在项目的 `manifest.json` 文件内完成了必要的权限声明以及网络域名白名单设置[^1]: ```json { "permissions": { "scope.camera": true, "scope.network": ["https://open.ys7.com"] }, ... } ``` #### 安装依赖库 接着安装官方推荐使用的 SDK 或者其他辅助工具包以便简化开发流程。如果存在针对 UniApp 的封装版本,则优先考虑使用该版本以减少兼容性问题的发生概率。 #### 编写核心逻辑代码 下面是一个简单的例子展示如何利用 JavaScript 发起请求并与页面交互从而达到控制目的。注意实际应用时应当按照最新文档调整参数名称和值: ```javascript // 在 methods 节点下定义方法 getVideoStream() { uni.request({ url: 'https://open.ys7.com/api/lapp/device/video/addr/get', method: 'POST', data: { deviceSerial: this.deviceInfo.serial, // 填入目标设备序列号 validateCode: this.validateCode // 验证码或其他验证方式的结果 }, success(res) { console.log('Get video stream address:', res.data); // 将返回的数据用于后续处理... } }); } controlPTZ(commandType) { const commands = ['up', 'down', 'left', 'right']; if (!commands.includes(commandType)) return; uni.request({ url: 'https://open.ys7.com/api/lapp/device/ptz/start', method: 'POST', data: { deviceSerial: this.deviceInfo.serial, channelNo: 1, command: commandType.toUpperCase(), speed: 50 // 可选参数,默认为50 }, success(res) { console.log(`Control PTZ ${commandType} result`, res); } }); } ``` 以上代码片段展示了两个主要的功能函数:一个是用来取得实时预览地址;另一个则是发送指令给指定的摄像机执行上下左右的动作。具体细节可能依据实际情况有所不同,请参照最新的API手册进行适当修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值