日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

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

發(fā)布時(shí)間:2023/12/18 vue 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue中实现视频直播(萤石云)/实时视频: 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

        • 法一:使用ezuikit-js插件(accessToken+url)
            • 1. 安裝
            • 2. 使用:
            • 3.初始化時(shí)可傳參數(shù):
            • 4.可調(diào)用的方法:
            • 5.螢石云:
            • 6.最終效果:
        • 法二:使用ezuikit.js文件(鏈接)
            • 1、[官網(wǎng)下載js包](https://open.ys7.com/mobile/download.html)
            • 2、(把下載好的ezuikit.js js包)放進(jìn)vue 的 static 下
            • 3、public在index.html引入
            • 4、使用:
        • 法三:后端只給設(shè)備號(hào)


法一:使用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', // 視頻容器IDaccessToken: 'at.3bvmj4ycamlgdwgw1ig1jruma0wpohl6-48zifyb39c-13t5am6-yukyi86mz',url: 'ezopen://open.ys7.com/203751922/1.live',audio: 0, // 是否默認(rèn)開(kāi)啟聲音 0 - 關(guān)閉 1 - 開(kāi)啟autoplay: true,width: 408,height: 237})},},beforeDestroy() {this.player && this.player.stop() //銷(xiāo)毀并停止直播視頻} } </script>
3.初始化時(shí)可傳參數(shù):
參數(shù)名類(lèi)型描述是否必選
idString播放器容器DOM的idY
accessTokenString授權(quán)過(guò)程獲取的access_tokenY
urlString視頻ezopen協(xié)議播放地址Y
audioint是否默認(rèn)開(kāi)啟聲音 1:打開(kāi)(默認(rèn)) 0:關(guān)閉N
widthint視頻寬度,默認(rèn)值為容器容器DOM寬度N
heightint視頻高度,默認(rèn)值為容器容器DOM高度N
templetestring播放器模板,可以通過(guò)選定模板,使用內(nèi)置的播放器樣式,組件 simple:極簡(jiǎn)版;standard:標(biāo)準(zhǔn)版;security:安防版(預(yù)覽回放);vioce:語(yǔ)音版N
headerArray視頻頭部可選UI組件,可選值:capturePicture:截圖,save:錄像保存,zoom:電子放大N
footerArray視頻底部部可選UI組件,可選值:talk:對(duì)講,broadcast:語(yǔ)音播報(bào),hd:高清標(biāo)清切換,fullScreen:全屏N
pluginArray按需加載插件,可選值: talk:對(duì)講N
handleSuccessfunction播放成功回調(diào)N
handleErrorfunction播放錯(cuò)誤回調(diào)N
openSoundCallBackfunction開(kāi)啟聲音回調(diào)N
closeSoundCallBackfunction關(guān)閉回調(diào)N
startSaveCallBackfunction開(kāi)始錄像回調(diào)N
stopSaveCallBackfunction結(jié)束錄像回調(diào)N
capturePictureCallBackfunction截圖回調(diào)N
fullScreenCallBackfunction全屏回調(diào)N
getOSDTimeCallBackfunction獲取OSD時(shí)間回調(diào)N
4.可調(diào)用的方法:
方法名類(lèi)型描述使用示例
playfunction開(kāi)始播放player.play()
stopfunction結(jié)束播放player.stop()
openSoundString開(kāi)啟聲音player.openSound()
closeSoundString關(guān)閉聲音player.closeSound()
startSaveint開(kāi)始錄像player.startSave()
stopSaveint結(jié)束錄像player.stopSave()
capturePicturefunction視頻截圖player.capturePicture()
fullScreenfunction全屏player.fullScreen()
getOSDTimefunction獲取播放時(shí)間回調(diào)player.getOSDTime()
startTalkfunction開(kāi)始對(duì)講player.startTalk()
stopTalkfunction結(jié)束對(duì)講player.stopTalk()
5.螢石云:

官網(wǎng)

開(kāi)發(fā)文檔

使用方法

6.最終效果:

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

優(yōu)點(diǎn):不需要做控件按鈕功能

適用情況:

1、官網(wǎng)下載js包

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

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

2、(把下載好的ezuikit.js js包)放進(jìn)vue 的 static 下

這里報(bào)錯(cuò)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,// 頁(yè)面跳轉(zhuǎn)時(shí)注意關(guān)閉視頻流,vue跳轉(zhuǎn)原有任務(wù)不會(huì)停止或者在beforeDestroy銷(xiāo)毀掉}},mounted(){},methods:{//獲取播放地址getVideoCameraAddr(id, index) {const This = thislet param = {id: id}videoCameraAddr(param).then(res => {if (res.data.code == 0) {This.formData.videoCamera = res.data.dataThis.palyer = nullsetTimeout(function () {This.player = new EZUIKit.EZUIPlayer('videoCamera')}, 0)} else {This.$message.error('獲取視頻監(jiān)控?cái)z相機(jī)播放地址失敗' + res.data.msg)}})},},beforeDestroy(){this.palyer = null} } </script>

法三:后端只給設(shè)備號(hào)

相關(guān)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 jqueryexport default {name: 'dashboard',data() {return {accessToken: '',liveAddress: [],diveType: '',players: [],}},methods: {// 獲取磅點(diǎn)攝像頭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 YappSecret: '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 當(dāng)前頁(yè)數(shù)pageSize: "100", // string true 每頁(yè)條數(shù)}videoCameraId(param).then(res => {if (res.success) {// 根據(jù)列表長(zhǎng)度獲取播放地址if (res.result.list.length <= 0) {This.$message.error('暫無(wú)數(shù)據(jù),磅點(diǎn)攝相機(jī)列表為空' + res.data.msg)} else {res.result.list.forEach((item, index) => {this.getDeviceInfo(item.id, index, item.deviceNumber, This.accessToken);})}} else {This.$message.error('獲取視頻監(jiān)控?cái)z相機(jī)ID列表失敗' + res.data.msg)}})},// 查詢(xún)?cè)O(shè)備類(lèi)型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 授權(quán)過(guò)程獲取的access_token YdeviceSerial: deviceNum, // G66585615 J29276929},"success": function (res) {if (res.code == 200) {if (res.data.model.indexOf('IPC') >= 0) { //攝像機(jī)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 { //錄像機(jī)this.diveType = 2;let tdS = [];// 獲取設(shè)備通道號(hào)$.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 授權(quán)過(guò)程獲取的access_token YdeviceSerial: 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 授權(quán)過(guò)程獲取的access_token YdeviceSerial: 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)}})},},//銷(xiāo)毀視頻destroyed() {for (var j = 0; j < this.players.length; j++) {this.players[j].stop();}} } </script>

總結(jié)

以上是生活随笔為你收集整理的vue中实现视频直播(萤石云)/实时视频:的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。