vue中实现视频直播(萤石云)/实时视频:

本文详细介绍了如何在Vue项目中集成ezuikit-js插件和ezuikit.js文件来实现萤石云视频直播的播放功能。包括安装步骤、初始化参数、可调用的方法以及实际应用案例。同时,还提供了后端仅提供设备号时的处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


法一:使用ezuikit-js插件(accessToken+url)

适用情况:

在这里插入图片描述

1. 安装
  npm install ezuikit-js --save
2. 使用:
<template>
	<div id="video-container"></div>
</template>

<script>
import  EZUIKit from 'ezuikit-js';
export default {
    name: '',
    data() {
        return {
        	player:null,
        }
    },
    created(){
    	this.getVideoData()
    },
    methods:{
    	getVideoData(){
    		....
    		this.player = new EZUIKit.EZUIKitPlayer({
     			id: 'video-container', // 视频容器ID
     			accessToken: 'at.3bvmj4ycamlgdwgw1ig1jruma0wpohl6-48zifyb39c-13t5am6-yukyi86mz',
   				url: 'ezopen://open.ys7.com/203751922/1.live',
   				audio: 0, // 是否默认开启声音 0 - 关闭 1 - 开启
   				autoplay: true,
                width: 408,
                height: 237
			})
    	},
    },
    beforeDestroy() {
        this.player && this.player.stop() //销毁并停止直播视频
    }
}
</script>
3.初始化时可传参数:
参数名类型描述是否必选
idString播放器容器DOM的idY
accessTokenString授权过程获取的access_tokenY
urlString视频ezopen协议播放地址Y
audioint是否默认开启声音 1:打开(默认) 0:关闭N
widthint视频宽度,默认值为容器容器DOM宽度N
heightint视频高度,默认值为容器容器DOM高度N
templetestring播放器模板,可以通过选定模板,使用内置的播放器样式,组件 simple:极简版;standard:标准版;security:安防版(预览回放);vioce:语音版N
headerArray视频头部可选UI组件,可选值:capturePicture:截图,save:录像保存,zoom:电子放大N
footerArray视频底部部可选UI组件,可选值:talk:对讲,broadcast:语音播报,hd:高清标清切换,fullScreen:全屏N
pluginArray按需加载插件,可选值: talk:对讲N
handleSuccessfunction播放成功回调N
handleErrorfunction播放错误回调N
openSoundCallBackfunction开启声音回调N
closeSoundCallBackfunction关闭回调N
startSaveCallBackfunction开始录像回调N
stopSaveCallBackfunction结束录像回调N
capturePictureCallBackfunction截图回调N
fullScreenCallBackfunction全屏回调N
getOSDTimeCallBackfunction获取OSD时间回调N
4.可调用的方法:
方法名类型描述使用示例
playfunction开始播放player.play()
stopfunction结束播放player.stop()
openSoundString开启声音player.openSound()
closeSoundString关闭声音player.closeSound()
startSaveint开始录像player.startSave()
stopSaveint结束录像player.stopSave()
capturePicturefunction视频截图player.capturePicture()
fullScreenfunction全屏player.fullScreen()
getOSDTimefunction获取播放时间回调player.getOSDTime()
startTalkfunction开始对讲player.startTalk()
stopTalkfunction结束对讲player.stopTalk()
5.萤石云:

官网

开发文档

使用方法

6.最终效果:

在这里插入图片描述

法二:使用ezuikit.js文件(链接)

优点:不需要做控件按钮功能

适用情况:

在这里插入图片描述

1、官网下载js包

https://open.ys7.com/mobile/download.html

资源地址:https://download.csdn.net/download/weixin_53791978/86512096

2、(把下载好的ezuikit.js js包)放进vue 的 static 下

在这里插入图片描述

这里报错ezuikit is not undefined,就放到public下

在这里插入图片描述

3、public在index.html引入
<script src="static/ezuikit.js"></script>
4、使用:
<video id="videoCamera"
     style="object-fit: fill; width: 100%; height: 100%; background: #000;"
     :src="formData.videoCamera" autoplay="true" controls playsInline webkit-playsinline>
</video>  //记得给宽高

<script>
export default{
	data(){
		return{
			formData:{},
			palyer:null,// 页面跳转时注意关闭视频流,vue跳转原有任务不会停止或者在beforeDestroy销毁掉
		}
	},
	mounted(){
	
	},
	methods:{
		//获取播放地址
        getVideoCameraAddr(id, index) {
            const This = this
            let param = {
                id: id
            }
            videoCameraAddr(param).then(res => {
                if (res.data.code == 0) {
                        This.formData.videoCamera = res.data.data
                        This.palyer = null
                        setTimeout(function () {
                            This.player = new EZUIKit.EZUIPlayer('videoCamera')
                        }, 0)
                } else {
                    This.$message.error('获取视频监控摄相机播放地址失败' + res.data.msg)
                }
            })
        },
	},
	beforeDestroy(){
		this.palyer = null
	}
}
</script>

在这里插入图片描述

法三:后端只给设备号

相关JS文件:https://download.csdn.net/download/weixin_53791978/87231692

在这里插入图片描述

<section class="sectionVideo">
  <div class="video_warp_item" v-for="(item, index) in liveAddress" :key="index">
     <video :id=item.tdh :src="item.url" autoplay muted controls playsInline webkit-playsinline></video>
  </div>
</section>
<script>
import { videoCameraId } from '@/api/manage/videoAPI.js'
import $ from 'jquery'  //  npm i jquery


export default {
    name: 'dashboard',
    data() {
        return {
            accessToken: '',
            liveAddress: [],
            diveType: '',
            players: [],
        }
    },
    methods: {
        // 获取磅点摄像头ID列表
        getbagndianID() {
            const This = this

            // 获取萤石云的accessToken
            $.ajax({
                "url": 'https://open.ys7.com/api/lapp/token/get',
                "type": 'POST',
                "dataType": "json",
                "data": {
                    appKey: '412f919adde14fe3af396d5bef2c6db1', //String	appKey	Y
                    appSecret: '7566546bfc7adc4f55b86af93703599c' //	String	appSecret	Y
                },
                "cache": false,
                "success": function (response) {
                    This.accessToken = response.data.accessToken;
                }
            })

            let param = {
                deptId: This.formData.deptId,
                stationId: This.formData.stationId,
                pageNum: "1", //	string	true	当前页数
                pageSize: "100", //	string	true	每页条数
            }
            videoCameraId(param).then(res => {
                if (res.success) {
                    // 根据列表长度获取播放地址
                    if (res.result.list.length <= 0) {
                        This.$message.error('暂无数据,磅点摄相机列表为空' + res.data.msg)
                    } else {
                        res.result.list.forEach((item, index) => {
                            this.getDeviceInfo(item.id, index, item.deviceNumber, This.accessToken);
                        })
                    }
                } else {
                    This.$message.error('获取视频监控摄相机ID列表失败' + res.data.msg)
                }
            })
        },
        // 查询设备类型
        getDeviceInfo(id, indexer, deviceNum, accessToken) {
            const that = this
            $.ajax({
                "url": 'https://open.ys7.com/api/lapp/device/info',
                "header": {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                "type": 'POST',
                "dataType": "json",
                "data": {
                    accessToken: accessToken, //	String	授权过程获取的access_token	Y
                    deviceSerial: deviceNum, // G66585615  J29276929
                },
                "success": function (res) {
                    if (res.code == 200) {
                        if (res.data.model.indexOf('IPC') >= 0) { //摄像机
                            this.diveType = 1;
                            that.liveAddress = []
                            this.getUrl(accessToken, deviceNum, 1);
                            setTimeout(() => {
                                if (that.liveAddress.length > 0) {
                                    that.players = [];
                                    that.liveAddress.forEach((item, i) => {
                                        let player = new EZUIKit.EZUIPlayer(item.tdh)
                                        that.players.push(player);
                                    })
                                }
                            }, 500)
                        } else { //录像机
                            this.diveType = 2;
                            let tdS = [];
                            // 获取设备通道号
                            $.ajax({
                                "url": 'https://open.ys7.com/api/lapp/device/camera/list',
                                "header": {
                                    'Content-Type': 'application/x-www-form-urlencoded' //multipart/form-data text/plain
                                },
                                "type": 'POST',
                                "dataType": "json",
                                "data": {
                                    accessToken: accessToken, //	String	授权过程获取的access_token	Y
                                    deviceSerial: deviceNum
                                },
                                "success": function (response) {
                                    response.data.forEach((item) => {
                                        if (item.status == 1) { tdS.push(item) }
                                    })
                                    that.liveAddress = []
                                    tdS.forEach((item) => {
                                        that.getUrl(accessToken, deviceNum, item.channelNo);
                                    })
                                    setTimeout(() => {
                                        if (that.liveAddress.length > 0) {
                                            that.players = [];
                                            that.liveAddress.forEach((item, i) => {
                                                let player = new EZUIKit.EZUIPlayer(item.tdh)
                                                that.players.push(player);
                                            })
                                        }
                                    }, 500)
                                }
                            })
                        }
                    }
                },
            });
        },
        // 获取视频播放地址
        getUrl(accessToken, id, typeId) {
            const that = this
            $.ajax({
                "url": 'https://open.ys7.com/api/lapp/v2/live/address/get',
                "type": 'POST',
                "data": {
                    accessToken: accessToken, //	String	授权过程获取的access_token	Y
                    deviceSerial: id,
                    protocol: 2,
                    channelNo: typeId,
                },
                "dataType": "json",
                "success": function (res) {
                    let item = {
                        tdh: 'm' + res.data.id,
                        url: res.data.url
                    }
                    that.liveAddress.push(item)
                }
            })
        },
    },
    //销毁视频
    destroyed() {
        for (var j = 0; j < this.players.length; j++) {
            this.players[j].stop();
        }
    }
}
</script>
Vue.js萤石监控可以通过以下步骤实现全屏功能。 首先,在Vue.js的组件中,需要引入萤石监控的SDK,以便能够与监控设备进行交互。可以通过在`<head>`标签中引入SDK的链接,或者使用NPM包管理工具进行安装。 接下来,在Vue.js的组件中,创建一个DOM元素,用于显示监控画面。可以使用`<div>`或者`<canvas>`等标签来创建DOM元素。 然后,在Vue.js的`mounted`生命周期钩子函数中,实例化萤石监控SDK,并将SDK的实例与之前创建的DOM元素进行绑定,以便能够将监控画面显示在这个DOM元素中。 在绑定完成后,可以通过调用SDK实例的方法,来加载监控设备的视频流,并将视频流显示在之前创建的DOM元素中。 最后,实现全屏功能可以通过在Vue.js的组件中添加一个按钮或者其他的交互元素,并在点击事件中调用浏览器的全屏API来实现。可以通过`document.documentElement.requestFullscreen()`或者`element.requestFullscreen()`方法来进入全屏模式,其中`element`是之前创建的DOM元素。 需要注意的是,在进入全屏模式时,需要浏览器的支持,不同的浏览器可能有不同的API调用方式。在调用全屏API之前,最好先进行一些兼容性检测,以确保在不同浏览器上都能正常运行。 以上就是使用Vue.js萤石监控实现全屏功能的基本步骤。具体的实现细节还需要根据具体的项目情况来调整和完善。
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sun Peng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值