类型:开发
描述:
This commit is contained in:
@@ -41,10 +41,11 @@ instance.interceptors.response.use(
|
|||||||
if (res.data.code == 200) {
|
if (res.data.code == 200) {
|
||||||
return res.data
|
return res.data
|
||||||
} else {
|
} else {
|
||||||
ElMessage({
|
console.error("接口请求错误:"+res.data.msg)
|
||||||
message: res.data.msg,
|
// ElMessage({
|
||||||
type: 'error'
|
// message: res.data.msg,
|
||||||
})
|
// type: 'error'
|
||||||
|
// })
|
||||||
return Promise.reject(res.data)
|
return Promise.reject(res.data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
BIN
src/assets/images/loading.gif
Normal file
BIN
src/assets/images/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -66,13 +66,20 @@
|
|||||||
import { postVideoControlApi,postVideoCollectApi } from '@/api/monitor'
|
import { postVideoControlApi,postVideoCollectApi } from '@/api/monitor'
|
||||||
import { getColletDiyApi } from '@/api/home'
|
import { getColletDiyApi } from '@/api/home'
|
||||||
import pubSub from 'pubsub-js'
|
import pubSub from 'pubsub-js'
|
||||||
const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
// const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
||||||
const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
// const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
||||||
const UP = 'UP' // 上转
|
// const UP = 'UP' // 上转
|
||||||
const DOWN = 'DOWN' // 下转
|
// const DOWN = 'DOWN' // 下转
|
||||||
const LEFT = 'LEFT' // 左转
|
// const LEFT = 'LEFT' // 左转
|
||||||
const RIGHT = 'RIGHT' // 右转
|
// const RIGHT = 'RIGHT' // 右转
|
||||||
const STOP = 'STOP' // 停止操作
|
// const STOP = 'STOP' // 停止操作
|
||||||
|
const Z00M_IN = 'zoomin' // 焦距变大
|
||||||
|
const Z00M_OUT = 'zoomout' // 焦距变小
|
||||||
|
const UP = 'up' // 上转
|
||||||
|
const DOWN = 'down' // 下转
|
||||||
|
const LEFT = 'left' // 左转
|
||||||
|
const RIGHT = 'right' // 右转
|
||||||
|
const STOP = 'stop' // 停止操作
|
||||||
let ACTION = '0'
|
let ACTION = '0'
|
||||||
let command = ref('')
|
let command = ref('')
|
||||||
|
|
||||||
@@ -149,6 +156,7 @@
|
|||||||
const handleAction = async (e) => {
|
const handleAction = async (e) => {
|
||||||
if (e == STOP) {
|
if (e == STOP) {
|
||||||
ACTION = '1'
|
ACTION = '1'
|
||||||
|
command.value = e
|
||||||
} else {
|
} else {
|
||||||
ACTION = '0'
|
ACTION = '0'
|
||||||
command.value = e
|
command.value = e
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
@click="handleItem(item)"
|
@click="handleItem(item)"
|
||||||
>
|
>
|
||||||
<div class="item-unfollow" @click.stop="handleCollect(item.cameraIndexCode, index)">取消关注</div>
|
<div class="item-unfollow" @click.stop="handleCollect(item.cameraIndexCode, index)">取消关注</div>
|
||||||
<video class="item-video" :id="'video' + index" muted autoplay :controls="false">
|
<video class="item-video" :id="'videoall' + index" muted autoplay :controls="false">
|
||||||
<source type="application/x-mpegURL" />
|
<source type="application/x-mpegURL" />
|
||||||
</video>
|
</video>
|
||||||
<p>
|
<p>
|
||||||
@@ -36,13 +36,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { getVideoListApi,getColletListApi } from '@/api/home'
|
import {getVideoListApi, getColletListApi, getPreviewUrlApi} from '@/api/home'
|
||||||
import { postVideoCollectApi } from '@/api/monitor'
|
import { postVideoCollectApi } from '@/api/monitor'
|
||||||
|
|
||||||
import primary from '@/assets/images/item-primary.png'
|
import primary from '@/assets/images/item-primary.png'
|
||||||
|
|
||||||
import Hls from 'hls.js'
|
import Hls from 'hls.js'
|
||||||
import pubSub from 'pubsub-js'
|
import pubSub from 'pubsub-js'
|
||||||
|
import mpegtsjs from "mpegts.js";
|
||||||
|
|
||||||
let modelValue = defineModel()
|
let modelValue = defineModel()
|
||||||
let isCollect = ref(0)
|
let isCollect = ref(0)
|
||||||
@@ -75,9 +76,13 @@
|
|||||||
getVideoList()
|
getVideoList()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const handleItem = (item) => {
|
const handleItem = async (item) => {
|
||||||
console.log(item, 'iscollect')
|
console.log(item, 'iscollect')
|
||||||
src.value = item.hlsUrl
|
let res = await getPreviewUrlApi({
|
||||||
|
cameraIndexCode: item.cameraIndexCode,
|
||||||
|
type: 'hls'
|
||||||
|
})
|
||||||
|
src.value = res.data.url
|
||||||
isCollect.value = item.isCollect
|
isCollect.value = item.isCollect
|
||||||
isDiy.value = item.isDiy
|
isDiy.value = item.isDiy
|
||||||
cameraIndexCode.value = item.cameraIndexCode
|
cameraIndexCode.value = item.cameraIndexCode
|
||||||
@@ -110,27 +115,77 @@
|
|||||||
list.value = []
|
list.value = []
|
||||||
getVideoList()
|
getVideoList()
|
||||||
}
|
}
|
||||||
|
const createPlayer = (cameraIndexCode,videoElement) => {
|
||||||
|
getPreviewUrlApi({
|
||||||
|
type: 'hls',
|
||||||
|
cameraIndexCode: cameraIndexCode
|
||||||
|
}).then(res=>{
|
||||||
|
const url = res.data.url;
|
||||||
|
if(url.startsWith('ws')){
|
||||||
|
const player = mpegtsjs.createPlayer({
|
||||||
|
url: url,
|
||||||
|
type: 'flv',
|
||||||
|
isLive: true,
|
||||||
|
hasAudio: false
|
||||||
|
})
|
||||||
|
player.attachMediaElement(videoElement)
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
// 错误处理和重连机制
|
||||||
|
player.on(mpegtsjs.Events.ERROR, (err) => {
|
||||||
|
player.unload();
|
||||||
|
console.error('播放器错误:', err)
|
||||||
|
// 3 秒后尝试重新加载
|
||||||
|
setTimeout(() => {
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const player = new Hls({
|
||||||
|
maxBufferLength: 10, // 最大缓冲长度(秒)
|
||||||
|
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
||||||
|
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
||||||
|
})
|
||||||
|
player.loadSource(url)
|
||||||
|
player.attachMedia(videoElement)
|
||||||
|
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
|
videoElement.play()
|
||||||
|
})
|
||||||
|
player.on(Hls.Events.ERROR, (event, data) => {
|
||||||
|
// 根据错误类型进行处理
|
||||||
|
if (data.fatal) {
|
||||||
|
switch (data.type) {
|
||||||
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||||
|
console.log('网络错误,尝试重新加载');
|
||||||
|
player.startLoad();
|
||||||
|
break;
|
||||||
|
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||||
|
console.log('媒体错误,尝试修复');
|
||||||
|
player.recoverMediaError();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('无法恢复的错误,销毁播放器');
|
||||||
|
// hls.destroy();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
const getVideoList = async () => {
|
const getVideoList = async () => {
|
||||||
let res = await getColletListApi(params)
|
let res = await getColletListApi(params)
|
||||||
list.value = res.data
|
list.value = res.data
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
list.value.forEach(async (item, index) => {
|
list.value.forEach(async (item, index) => {
|
||||||
var video = document.getElementById(`video${index}`)
|
var video = document.getElementById(`videoall${index}`)
|
||||||
const hls = new Hls({
|
createPlayer(item.cameraIndexCode,video);
|
||||||
enableWorker: false, // 禁用 Worker 来避免额外的线程
|
|
||||||
enableSoftwareAES: true, // 使用软件解码器以避免硬件解码的额外请求
|
|
||||||
cache: true, // 启用缓存
|
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
|
||||||
maxBufferSize: 20 * 1000 * 1000 // 最大缓冲大小(字节)
|
|
||||||
})
|
|
||||||
hls.loadSource(item.hlsUrl)
|
|
||||||
hls.attachMedia(video)
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
||||||
video.play()
|
|
||||||
})
|
|
||||||
hlsRefs.push(hls)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,12 @@ let isCollect = ref(0)
|
|||||||
let hlsRefs = []
|
let hlsRefs = []
|
||||||
let timer = null
|
let timer = null
|
||||||
let isDiy = ref(0)
|
let isDiy = ref(0)
|
||||||
const handleItem = (item) => {
|
const handleItem = async (item) => {
|
||||||
src.value = item.hlsUrl
|
let res = await getPreviewUrlApi({
|
||||||
|
cameraIndexCode: item.cameraIndexCode,
|
||||||
|
type: 'hls'
|
||||||
|
})
|
||||||
|
src.value = res.data.url
|
||||||
cameraIndexCode.value = item.cameraIndexCode
|
cameraIndexCode.value = item.cameraIndexCode
|
||||||
isCollect.value = item.isCollect
|
isCollect.value = item.isCollect
|
||||||
isDiy.value = item.isDiy
|
isDiy.value = item.isDiy
|
||||||
@@ -87,6 +91,69 @@ let isCollect = ref(0)
|
|||||||
src.value = res.data.url
|
src.value = res.data.url
|
||||||
videoShow.value = true
|
videoShow.value = true
|
||||||
}
|
}
|
||||||
|
const createPlayer = (cameraIndexCode,videoElement) => {
|
||||||
|
getPreviewUrlApi({
|
||||||
|
type: 'hls',
|
||||||
|
cameraIndexCode: cameraIndexCode
|
||||||
|
}).then(res=>{
|
||||||
|
const url = res.data.url;
|
||||||
|
if(url.startsWith('ws')){
|
||||||
|
const player = mpegtsjs.createPlayer({
|
||||||
|
url: url,
|
||||||
|
type: 'flv',
|
||||||
|
isLive: true,
|
||||||
|
hasAudio: false
|
||||||
|
})
|
||||||
|
player.attachMediaElement(videoElement)
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
// 错误处理和重连机制
|
||||||
|
player.on(mpegtsjs.Events.ERROR, (err) => {
|
||||||
|
player.unload();
|
||||||
|
console.error('播放器错误:', err)
|
||||||
|
// 3 秒后尝试重新加载
|
||||||
|
setTimeout(() => {
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const player = new Hls({
|
||||||
|
maxBufferLength: 10, // 最大缓冲长度(秒)
|
||||||
|
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
||||||
|
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
||||||
|
})
|
||||||
|
player.loadSource(url)
|
||||||
|
player.attachMedia(videoElement)
|
||||||
|
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
|
videoElement.play()
|
||||||
|
})
|
||||||
|
player.on(Hls.Events.ERROR, (event, data) => {
|
||||||
|
// 根据错误类型进行处理
|
||||||
|
if (data.fatal) {
|
||||||
|
switch (data.type) {
|
||||||
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||||
|
console.log('网络错误,尝试重新加载');
|
||||||
|
player.startLoad();
|
||||||
|
break;
|
||||||
|
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||||
|
console.log('媒体错误,尝试修复');
|
||||||
|
player.recoverMediaError();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('无法恢复的错误,销毁播放器');
|
||||||
|
// hls.destroy();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
const getVideoList = async () => {
|
const getVideoList = async () => {
|
||||||
let res = await getColletListApi({
|
let res = await getColletListApi({
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
@@ -97,26 +164,7 @@ let isCollect = ref(0)
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
list.value.forEach(async (item, index) => {
|
list.value.forEach(async (item, index) => {
|
||||||
var videoElement = document.getElementById(`video${index}`)
|
var videoElement = document.getElementById(`video${index}`)
|
||||||
const player = mpegtsjs.createPlayer({
|
createPlayer(item.cameraIndexCode,videoElement);
|
||||||
url: item.hlsUrl,
|
|
||||||
type: 'flv',
|
|
||||||
isLive: true,
|
|
||||||
hasAudio: false
|
|
||||||
})
|
|
||||||
player.attachMediaElement(videoElement)
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
|
|
||||||
// 错误处理和重连机制
|
|
||||||
player.on('error', (err) => {
|
|
||||||
console.error('播放器错误:', err)
|
|
||||||
// 3 秒后尝试重新加载
|
|
||||||
setTimeout(() => {
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
hlsRefs.push(player)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,14 +35,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<video
|
<video
|
||||||
class="video-item__video"
|
class="video-item__video"
|
||||||
:id="'monitorVideo' + element.cameraIndexCode"
|
:id="'collectmonitorVideo' + element.cameraIndexCode"
|
||||||
preload="auto"
|
preload="auto"
|
||||||
muted
|
muted
|
||||||
autoplay
|
autoplay
|
||||||
:controls="false"
|
:controls="false"
|
||||||
/>
|
/>
|
||||||
<p class="video-item__title--primary">
|
<p class="video-item__title--primary">
|
||||||
{{ element.cameraName || element.scenicAreaId }}
|
{{ element.cameraName || element.cameraIndexCode }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -52,29 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="pagination">
|
|
||||||
<el-pagination
|
|
||||||
v-model:current-page="params.pageNum"
|
|
||||||
:page-size="params.pageSize"
|
|
||||||
:total="total"
|
|
||||||
background
|
|
||||||
layout="prev, pager, next"
|
|
||||||
@current-change="currentChange"
|
|
||||||
/>
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <ul class="videos">
|
|
||||||
<li class="video-item" v-for="item in 8" :key="item">
|
|
||||||
<img src="@/assets/images/sxzd.png" alt="" />
|
|
||||||
<p>
|
|
||||||
<span>核心路段:这是一条信息说明</span>
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
</ul> -->
|
|
||||||
<!-- <div class="pagination-box">
|
|
||||||
<el-pagination background layout="prev, pager, next" :total="1000" />
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
<VideoDialog v-model="show" :cameraIndexCode="cameraIndexCode" @isDiyChange="isDiyChange" :isDiy="isDiy" :isCollect="isCollect" :src="videoSrc" />
|
<VideoDialog v-model="show" :cameraIndexCode="cameraIndexCode" @isDiyChange="isDiyChange" :isDiy="isDiy" :isCollect="isCollect" :src="videoSrc" />
|
||||||
</template>
|
</template>
|
||||||
@@ -94,13 +72,20 @@
|
|||||||
import emptyIco from '@/assets/images/n-icon.png'
|
import emptyIco from '@/assets/images/n-icon.png'
|
||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
import mpegtsjs from "mpegts.js";
|
import mpegtsjs from "mpegts.js";
|
||||||
const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
// const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
||||||
const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
// const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
||||||
const UP = 'UP' // 上转
|
// const UP = 'UP' // 上转
|
||||||
const DOWN = 'DOWN' // 下转
|
// const DOWN = 'DOWN' // 下转
|
||||||
const LEFT = 'LEFT' // 左转
|
// const LEFT = 'LEFT' // 左转
|
||||||
const RIGHT = 'RIGHT' // 右转
|
// const RIGHT = 'RIGHT' // 右转
|
||||||
const STOP = 'STOP' // 停止操作
|
// const STOP = 'STOP' // 停止操作
|
||||||
|
const Z00M_IN = 'zoomin' // 焦距变大
|
||||||
|
const Z00M_OUT = 'zoomout' // 焦距变小
|
||||||
|
const UP = 'up' // 上转
|
||||||
|
const DOWN = 'down' // 下转
|
||||||
|
const LEFT = 'left' // 左转
|
||||||
|
const RIGHT = 'right' // 右转
|
||||||
|
const STOP = 'stop' // 停止操作
|
||||||
let cond = ref(false)
|
let cond = ref(false)
|
||||||
let ACTION = '0'
|
let ACTION = '0'
|
||||||
let hlsRefs = []
|
let hlsRefs = []
|
||||||
@@ -170,7 +155,6 @@
|
|||||||
params.businessVideoDisplayPosition = ''
|
params.businessVideoDisplayPosition = ''
|
||||||
let res = await getVideCollectCate(params)
|
let res = await getVideCollectCate(params)
|
||||||
videoList.value = res.data
|
videoList.value = res.data
|
||||||
console.log(res,videoList.value.length,'ressssssssssssss')
|
|
||||||
if(videoList.value.length<=3){
|
if(videoList.value.length<=3){
|
||||||
grad.value = 3
|
grad.value = 3
|
||||||
}else if(videoList.value.length<=6){
|
}else if(videoList.value.length<=6){
|
||||||
@@ -206,6 +190,7 @@
|
|||||||
const handleAction = async (e) => {
|
const handleAction = async (e) => {
|
||||||
if (e == STOP) {
|
if (e == STOP) {
|
||||||
ACTION = '1'
|
ACTION = '1'
|
||||||
|
command.value = e
|
||||||
} else {
|
} else {
|
||||||
ACTION = '0'
|
ACTION = '0'
|
||||||
command.value = e
|
command.value = e
|
||||||
@@ -280,6 +265,69 @@
|
|||||||
if (type == 100) initVideo()
|
if (type == 100) initVideo()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
const createPlayer = (cameraIndexCode,videoElement) => {
|
||||||
|
getPreviewUrlApi({
|
||||||
|
type: 'hls',
|
||||||
|
cameraIndexCode: cameraIndexCode
|
||||||
|
}).then(res=>{
|
||||||
|
const url = res.data.url;
|
||||||
|
if(url.startsWith('ws')){
|
||||||
|
const player = mpegtsjs.createPlayer({
|
||||||
|
url: url,
|
||||||
|
type: 'flv',
|
||||||
|
isLive: true,
|
||||||
|
hasAudio: false
|
||||||
|
})
|
||||||
|
player.attachMediaElement(videoElement)
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
// 错误处理和重连机制
|
||||||
|
player.on(mpegtsjs.Events.ERROR, (err) => {
|
||||||
|
player.unload();
|
||||||
|
console.error('播放器错误:', err)
|
||||||
|
// 3 秒后尝试重新加载
|
||||||
|
setTimeout(() => {
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const player = new Hls({
|
||||||
|
maxBufferLength: 10, // 最大缓冲长度(秒)
|
||||||
|
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
||||||
|
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
||||||
|
})
|
||||||
|
player.loadSource(url)
|
||||||
|
player.attachMedia(videoElement)
|
||||||
|
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
|
videoElement.play()
|
||||||
|
})
|
||||||
|
player.on(Hls.Events.ERROR, (event, data) => {
|
||||||
|
// 根据错误类型进行处理
|
||||||
|
if (data.fatal) {
|
||||||
|
switch (data.type) {
|
||||||
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||||
|
console.log('网络错误,尝试重新加载');
|
||||||
|
player.startLoad();
|
||||||
|
break;
|
||||||
|
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||||
|
console.log('媒体错误,尝试修复');
|
||||||
|
player.recoverMediaError();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('无法恢复的错误,销毁播放器');
|
||||||
|
// hls.destroy();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
const initVideo = () => {
|
const initVideo = () => {
|
||||||
clearHlsRefs()
|
clearHlsRefs()
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -287,42 +335,8 @@
|
|||||||
|
|
||||||
it.videos.forEach((item,index)=>{
|
it.videos.forEach((item,index)=>{
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const video = document.getElementById(`monitorVideo${item.cameraIndexCode}`)
|
const video = document.getElementById(`collectmonitorVideo${item.cameraIndexCode}`)
|
||||||
if(item.hlsUrl.startsWith('ws')){
|
createPlayer(item.cameraIndexCode,video);
|
||||||
const player = mpegtsjs.createPlayer({
|
|
||||||
url: item.hlsUrl,
|
|
||||||
type: 'flv',
|
|
||||||
isLive: true,
|
|
||||||
hasAudio: false
|
|
||||||
})
|
|
||||||
player.attachMediaElement(video)
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
|
|
||||||
// 错误处理和重连机制
|
|
||||||
player.on('error', (err) => {
|
|
||||||
// 3 秒后尝试重新加载
|
|
||||||
setTimeout(() => {
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
if(item.hlsUrl){
|
|
||||||
const hls = new Hls({
|
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
|
||||||
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
|
||||||
})
|
|
||||||
hls.loadSource(item.hlsUrl)
|
|
||||||
hls.attachMedia(video)
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
||||||
video.play()
|
|
||||||
})
|
|
||||||
hlsRefs.push(hls)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<video
|
<video
|
||||||
class="video-item__video"
|
class="video-item__video"
|
||||||
:id="'monitorVideo' + index"
|
:id="'hotelmonitorVideo' + index"
|
||||||
preload="auto"
|
preload="auto"
|
||||||
muted
|
muted
|
||||||
autoplay
|
autoplay
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
<source type="application/x-mpegURL" />
|
<source type="application/x-mpegURL" />
|
||||||
</video>
|
</video>
|
||||||
<p class="video-item__title--primary">
|
<p class="video-item__title--primary">
|
||||||
{{ item.cameraName || item.scenicAreaId }}
|
{{ item.cameraName || item.cameraIndexCode }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -146,15 +146,15 @@
|
|||||||
class="item"
|
class="item"
|
||||||
v-for="(item, index) in videoList"
|
v-for="(item, index) in videoList"
|
||||||
:key="index"
|
:key="index"
|
||||||
@click="handleItemVideo(item.hlsUrl, 101, item.handleItemVideo,item)"
|
@click="handleItemVideo(item.hlsUrl, 101, item.cameraIndexCode,item)"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p class="item-title--primary">
|
<p class="item-title--primary">
|
||||||
{{ item.cameraName || item.scenicAreaId }}
|
{{ item.cameraName || item.cameraIndexCode }}
|
||||||
</p>
|
</p>
|
||||||
<video
|
<video
|
||||||
class="item-img"
|
class="item-img"
|
||||||
:id="'monitorVideo' + index"
|
:id="'hotelmonitorVideo' + index"
|
||||||
muted
|
muted
|
||||||
autoplay
|
autoplay
|
||||||
:controls="false"
|
:controls="false"
|
||||||
@@ -197,13 +197,20 @@
|
|||||||
import emptyIco from '@/assets/images/n-icon.png'
|
import emptyIco from '@/assets/images/n-icon.png'
|
||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
import mpegtsjs from "mpegts.js";
|
import mpegtsjs from "mpegts.js";
|
||||||
const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
// const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
||||||
const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
// const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
||||||
const UP = 'UP' // 上转
|
// const UP = 'UP' // 上转
|
||||||
const DOWN = 'DOWN' // 下转
|
// const DOWN = 'DOWN' // 下转
|
||||||
const LEFT = 'LEFT' // 左转
|
// const LEFT = 'LEFT' // 左转
|
||||||
const RIGHT = 'RIGHT' // 右转
|
// const RIGHT = 'RIGHT' // 右转
|
||||||
const STOP = 'STOP' // 停止操作
|
// const STOP = 'STOP' // 停止操作
|
||||||
|
const Z00M_IN = 'zoomin' // 焦距变大
|
||||||
|
const Z00M_OUT = 'zoomout' // 焦距变小
|
||||||
|
const UP = 'up' // 上转
|
||||||
|
const DOWN = 'down' // 下转
|
||||||
|
const LEFT = 'left' // 左转
|
||||||
|
const RIGHT = 'right' // 右转
|
||||||
|
const STOP = 'stop' // 停止操作
|
||||||
let cond = ref(false)
|
let cond = ref(false)
|
||||||
let ACTION = '0'
|
let ACTION = '0'
|
||||||
let hlsRefs = []
|
let hlsRefs = []
|
||||||
@@ -259,6 +266,7 @@
|
|||||||
const handleAction = async (e) => {
|
const handleAction = async (e) => {
|
||||||
if (e == STOP) {
|
if (e == STOP) {
|
||||||
ACTION = '1'
|
ACTION = '1'
|
||||||
|
command.value = e
|
||||||
} else {
|
} else {
|
||||||
ACTION = '0'
|
ACTION = '0'
|
||||||
command.value = e
|
command.value = e
|
||||||
@@ -311,6 +319,69 @@
|
|||||||
videoList.value = []
|
videoList.value = []
|
||||||
getRegionsList()
|
getRegionsList()
|
||||||
}
|
}
|
||||||
|
const createPlayer = (cameraIndexCode,videoElement) => {
|
||||||
|
getPreviewUrlApi({
|
||||||
|
type: 'hls',
|
||||||
|
cameraIndexCode: cameraIndexCode
|
||||||
|
}).then(res=>{
|
||||||
|
const url = res.data.url;
|
||||||
|
if(url.startsWith('ws')){
|
||||||
|
const player = mpegtsjs.createPlayer({
|
||||||
|
url: url,
|
||||||
|
type: 'flv',
|
||||||
|
isLive: true,
|
||||||
|
hasAudio: false
|
||||||
|
})
|
||||||
|
player.attachMediaElement(videoElement)
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
// 错误处理和重连机制
|
||||||
|
player.on(mpegtsjs.Events.ERROR, (err) => {
|
||||||
|
player.unload();
|
||||||
|
console.error('播放器错误:', err)
|
||||||
|
// 3 秒后尝试重新加载
|
||||||
|
setTimeout(() => {
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const player = new Hls({
|
||||||
|
maxBufferLength: 10, // 最大缓冲长度(秒)
|
||||||
|
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
||||||
|
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
||||||
|
})
|
||||||
|
player.loadSource(url)
|
||||||
|
player.attachMedia(videoElement)
|
||||||
|
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
|
videoElement.play()
|
||||||
|
})
|
||||||
|
player.on(Hls.Events.ERROR, (event, data) => {
|
||||||
|
// 根据错误类型进行处理
|
||||||
|
if (data.fatal) {
|
||||||
|
switch (data.type) {
|
||||||
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||||
|
console.log('网络错误,尝试重新加载');
|
||||||
|
player.startLoad();
|
||||||
|
break;
|
||||||
|
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||||
|
console.log('媒体错误,尝试修复');
|
||||||
|
player.recoverMediaError();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('无法恢复的错误,销毁播放器');
|
||||||
|
// hls.destroy();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
hlsRefs.push(player)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
//获取酒店视频列表
|
//获取酒店视频列表
|
||||||
const getRegionsList = async()=>{
|
const getRegionsList = async()=>{
|
||||||
clearHlsRefs()
|
clearHlsRefs()
|
||||||
@@ -325,59 +396,8 @@
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if(!videoList.value.length) return false
|
if(!videoList.value.length) return false
|
||||||
videoList.value.forEach(async (x, index) => {
|
videoList.value.forEach(async (x, index) => {
|
||||||
const video = document.getElementById(`monitorVideo${index}`)
|
const video = document.getElementById(`hotelmonitorVideo${index}`)
|
||||||
if(x.hlsUrl.startsWith('ws')){
|
createPlayer(x.cameraIndexCode,video);
|
||||||
const player = mpegtsjs.createPlayer({
|
|
||||||
url: x.hlsUrl,
|
|
||||||
type: 'flv',
|
|
||||||
isLive: true,
|
|
||||||
hasAudio: false
|
|
||||||
})
|
|
||||||
player.attachMediaElement(video)
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
// 错误处理和重连机制
|
|
||||||
player.on('error', (err) => {
|
|
||||||
// 3 秒后尝试重新加载
|
|
||||||
setTimeout(() => {
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
const hls = new Hls({
|
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
|
||||||
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
|
||||||
})
|
|
||||||
hls.loadSource(x.hlsUrl)
|
|
||||||
hls.attachMedia(video)
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
||||||
video.play()
|
|
||||||
})
|
|
||||||
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
||||||
console.error('HLS 播放器遇到错误:', data);
|
|
||||||
// 根据错误类型进行处理
|
|
||||||
// initVideo()
|
|
||||||
if (data.fatal) {
|
|
||||||
switch (data.type) {
|
|
||||||
case Hls.ErrorTypes.NETWORK_ERROR:
|
|
||||||
console.log('网络错误,尝试重新加载');
|
|
||||||
hls.startLoad();
|
|
||||||
break;
|
|
||||||
case Hls.ErrorTypes.MEDIA_ERROR:
|
|
||||||
console.log('媒体错误,尝试修复');
|
|
||||||
hls.recoverMediaError();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log('无法恢复的错误,销毁播放器');
|
|
||||||
// hls.destroy();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}})
|
|
||||||
hlsRefs.push(hls)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -392,7 +412,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
let thisVideo = ref(null)
|
let thisVideo = ref(null)
|
||||||
const handleItemVideo = (url, type, code,item) => {
|
const handleItemVideo = async (url, type, code, item) => {
|
||||||
|
let res = await getPreviewUrlApi({
|
||||||
|
cameraIndexCode: code,
|
||||||
|
type: 'hls'
|
||||||
|
})
|
||||||
|
url = res.data.url
|
||||||
thisVideo.value = item
|
thisVideo.value = item
|
||||||
videoLog.value = 2
|
videoLog.value = 2
|
||||||
cameraIndexCode.value = code
|
cameraIndexCode.value = code
|
||||||
@@ -436,40 +461,8 @@
|
|||||||
clearHlsRefs()
|
clearHlsRefs()
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
videoList.value.forEach(async (item, index) => {
|
videoList.value.forEach(async (item, index) => {
|
||||||
const video = document.getElementById(`monitorVideo${index}`)
|
const video = document.getElementById(`hotelmonitorVideo${index}`)
|
||||||
if(item.hlsUrl.startsWith('ws')){
|
createPlayer(item.cameraIndexCode,video);
|
||||||
var player = mpegtsjs.createPlayer({
|
|
||||||
url: item.hlsUrl,
|
|
||||||
type: 'flv',
|
|
||||||
isLive: true,
|
|
||||||
hasAudio: false
|
|
||||||
})
|
|
||||||
player.attachMediaElement(video)
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
|
|
||||||
// 错误处理和重连机制
|
|
||||||
player.on('error', (err) => {
|
|
||||||
// 3 秒后尝试重新加载
|
|
||||||
setTimeout(() => {
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
const hls = new Hls({
|
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
|
||||||
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
|
||||||
})
|
|
||||||
hls.loadSource(item.hlsUrl)
|
|
||||||
hls.attachMedia(video)
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
||||||
video.play()
|
|
||||||
})
|
|
||||||
hlsRefs.push(hls)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,16 +93,21 @@
|
|||||||
@click.stop="handleCollect(item.cameraIndexCode, item.isCollect, index)"
|
@click.stop="handleCollect(item.cameraIndexCode, item.isCollect, index)"
|
||||||
>关注
|
>关注
|
||||||
</div>
|
</div>
|
||||||
|
<view class="video-item__video">
|
||||||
<video
|
<video
|
||||||
class="video-item__video"
|
|
||||||
:id="'monitorVideo' + index"
|
:id="'monitorVideo' + index"
|
||||||
preload="auto"
|
preload="auto"
|
||||||
|
class="video-item__video"
|
||||||
muted
|
muted
|
||||||
autoplay
|
autoplay
|
||||||
:controls="false"
|
:controls="false"
|
||||||
>
|
>
|
||||||
|
|
||||||
<source type="application/x-mpegURL"/>
|
<source type="application/x-mpegURL"/>
|
||||||
</video>
|
</video>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
|
||||||
<p class="video-item__title--primary">
|
<p class="video-item__title--primary">
|
||||||
{{ item.cameraName || item.cameraIndexCode }}
|
{{ item.cameraName || item.cameraIndexCode }}
|
||||||
</p>
|
</p>
|
||||||
@@ -171,7 +176,7 @@
|
|||||||
class="item"
|
class="item"
|
||||||
v-for="(item, index) in videoList"
|
v-for="(item, index) in videoList"
|
||||||
:key="index"
|
:key="index"
|
||||||
@click="handleItemVideo(item.hlsUrl, 101, item.handleItemVideo,item)"
|
@click="handleItemVideo(item.hlsUrl, 101, item.cameraIndexCode,item)"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p class="item-title--primary">
|
<p class="item-title--primary">
|
||||||
@@ -212,13 +217,20 @@ import pubSub from 'pubsub-js'
|
|||||||
import Hls from 'hls.js'
|
import Hls from 'hls.js'
|
||||||
import HlsPlayer from "@/components/HlsPlayer/index.vue";
|
import HlsPlayer from "@/components/HlsPlayer/index.vue";
|
||||||
|
|
||||||
const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
// const Z00M_IN = 'ZOOM_IN' // 焦距变大
|
||||||
const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
// const Z00M_OUT = 'ZOOM_OUT' // 焦距变小
|
||||||
const UP = 'UP' // 上转
|
// const UP = 'UP' // 上转
|
||||||
const DOWN = 'DOWN' // 下转
|
// const DOWN = 'DOWN' // 下转
|
||||||
const LEFT = 'LEFT' // 左转
|
// const LEFT = 'LEFT' // 左转
|
||||||
const RIGHT = 'RIGHT' // 右转
|
// const RIGHT = 'RIGHT' // 右转
|
||||||
const STOP = 'STOP' // 停止操作
|
// const STOP = 'STOP' // 停止操作
|
||||||
|
const Z00M_IN = 'zoomin' // 焦距变大
|
||||||
|
const Z00M_OUT = 'zoomout' // 焦距变小
|
||||||
|
const UP = 'up' // 上转
|
||||||
|
const DOWN = 'down' // 下转
|
||||||
|
const LEFT = 'left' // 左转
|
||||||
|
const RIGHT = 'right' // 右转
|
||||||
|
const STOP = 'stop' // 停止操作
|
||||||
let ACTION = '0'
|
let ACTION = '0'
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
@@ -267,62 +279,7 @@ const initVideo = () => {
|
|||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
videoList.value.forEach(async (item, index) => {
|
videoList.value.forEach(async (item, index) => {
|
||||||
const videoElement = document.getElementById(`monitorVideo${index}`)
|
const videoElement = document.getElementById(`monitorVideo${index}`)
|
||||||
if(item.hlsUrl.startsWith("ws")){
|
createPlayer(item.cameraIndexCode,videoElement);
|
||||||
const player = mpegtsjs.createPlayer({
|
|
||||||
url: item.hlsUrl,
|
|
||||||
type: 'flv',
|
|
||||||
isLive: true,
|
|
||||||
hasAudio: false
|
|
||||||
})
|
|
||||||
player.attachMediaElement(videoElement)
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
|
|
||||||
// 错误处理和重连机制
|
|
||||||
player.on('error', (err) => {
|
|
||||||
console.error('播放器错误:', err)
|
|
||||||
// 3 秒后尝试重新加载
|
|
||||||
setTimeout(() => {
|
|
||||||
player.load()
|
|
||||||
player.play()
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
hlsRefs.push(player)
|
|
||||||
}else{
|
|
||||||
const player = new Hls({
|
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
|
||||||
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
|
||||||
})
|
|
||||||
player.loadSource(item.hlsUrl)
|
|
||||||
player.attachMedia(videoElement)
|
|
||||||
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
||||||
videoElement.play()
|
|
||||||
})
|
|
||||||
player.on(Hls.Events.ERROR, (event, data) => {
|
|
||||||
// console.error('HLS 播放器遇到错误:', data);
|
|
||||||
// hls.startLoad();
|
|
||||||
// initVideo()
|
|
||||||
// 根据错误类型进行处理
|
|
||||||
if (data.fatal) {
|
|
||||||
switch (data.type) {
|
|
||||||
case Hls.ErrorTypes.NETWORK_ERROR:
|
|
||||||
console.log('网络错误,尝试重新加载');
|
|
||||||
player.startLoad();
|
|
||||||
break;
|
|
||||||
case Hls.ErrorTypes.MEDIA_ERROR:
|
|
||||||
console.log('媒体错误,尝试修复');
|
|
||||||
player.recoverMediaError();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log('无法恢复的错误,销毁播放器');
|
|
||||||
// hls.destroy();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
hlsRefs.push(player)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -388,7 +345,12 @@ const handleBack = () => {
|
|||||||
initVideo()
|
initVideo()
|
||||||
}
|
}
|
||||||
let thisVideo = ref(null)
|
let thisVideo = ref(null)
|
||||||
const handleItemVideo = (url, type, code, item) => {
|
const handleItemVideo = async (url, type, code, item) => {
|
||||||
|
let res = await getPreviewUrlApi({
|
||||||
|
cameraIndexCode: code,
|
||||||
|
type: 'hls'
|
||||||
|
})
|
||||||
|
url = res.data.url
|
||||||
thisVideo.value = item
|
thisVideo.value = item
|
||||||
videoLog.value = 2
|
videoLog.value = 2
|
||||||
cameraIndexCode.value = code
|
cameraIndexCode.value = code
|
||||||
@@ -407,6 +369,7 @@ const handleItemVideo = (url, type, code, item) => {
|
|||||||
hlsRef.on('error', (err) => {
|
hlsRef.on('error', (err) => {
|
||||||
console.error('播放器错误:', err)
|
console.error('播放器错误:', err)
|
||||||
// 3 秒后尝试重新加载
|
// 3 秒后尝试重新加载
|
||||||
|
hlsRef.unload()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hlsRef.load()
|
hlsRef.load()
|
||||||
hlsRef.play()
|
hlsRef.play()
|
||||||
@@ -431,6 +394,7 @@ const handleItemVideo = (url, type, code, item) => {
|
|||||||
const handleAction = async (e) => {
|
const handleAction = async (e) => {
|
||||||
if (e == STOP) {
|
if (e == STOP) {
|
||||||
ACTION = '1'
|
ACTION = '1'
|
||||||
|
command.value = e
|
||||||
} else {
|
} else {
|
||||||
ACTION = '0'
|
ACTION = '0'
|
||||||
command.value = e
|
command.value = e
|
||||||
@@ -461,7 +425,6 @@ const handleCamera = async (itemCode, resource) => {
|
|||||||
type: 'hls',
|
type: 'hls',
|
||||||
cameraIndexCode: itemCode
|
cameraIndexCode: itemCode
|
||||||
})
|
})
|
||||||
console.log(res, 'rrrrrrrrrrrrrr')
|
|
||||||
cameraIndexCode.value = itemCode;
|
cameraIndexCode.value = itemCode;
|
||||||
isCollect.value = resource.isCollect
|
isCollect.value = resource.isCollect
|
||||||
isDiy.value = resource.isDiy
|
isDiy.value = resource.isDiy
|
||||||
@@ -510,29 +473,15 @@ watch(
|
|||||||
},
|
},
|
||||||
{immediate: true}
|
{immediate: true}
|
||||||
)
|
)
|
||||||
const getVideoList = async (val) => {
|
const createPlayer = (cameraIndexCode,videoElement) => {
|
||||||
try {
|
getPreviewUrlApi({
|
||||||
if (loading.value) return
|
type: 'hls',
|
||||||
loading.value = true
|
cameraIndexCode: cameraIndexCode
|
||||||
if (val == 3) {
|
}).then(res=>{
|
||||||
params.businessVideoDisplayPosition = ''
|
const url = res.data.url;
|
||||||
} else {
|
if(url.startsWith('ws')){
|
||||||
params.businessVideoDisplayPosition = navList.value[current.value]
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = await getVideoListApi(params)
|
|
||||||
total.value = res.total
|
|
||||||
if (res.data.length > 0) {
|
|
||||||
|
|
||||||
videoList.value = res.data
|
|
||||||
// console.log(videoList.value,'1111111111111111111111')
|
|
||||||
// postVideoRemain()
|
|
||||||
nextTick(() => {
|
|
||||||
videoList.value.forEach(async (x, index) => {
|
|
||||||
const videoElement = document.getElementById(`monitorVideo${index}`)
|
|
||||||
if(x.hlsUrl.startsWith('ws')){
|
|
||||||
const player = mpegtsjs.createPlayer({
|
const player = mpegtsjs.createPlayer({
|
||||||
url: x.hlsUrl,
|
url: url,
|
||||||
type: 'flv',
|
type: 'flv',
|
||||||
isLive: true,
|
isLive: true,
|
||||||
hasAudio: false
|
hasAudio: false
|
||||||
@@ -540,9 +489,9 @@ const getVideoList = async (val) => {
|
|||||||
player.attachMediaElement(videoElement)
|
player.attachMediaElement(videoElement)
|
||||||
player.load()
|
player.load()
|
||||||
player.play()
|
player.play()
|
||||||
|
|
||||||
// 错误处理和重连机制
|
// 错误处理和重连机制
|
||||||
player.on('error', (err) => {
|
player.on(mpegtsjs.Events.ERROR, (err) => {
|
||||||
|
player.unload();
|
||||||
console.error('播放器错误:', err)
|
console.error('播放器错误:', err)
|
||||||
// 3 秒后尝试重新加载
|
// 3 秒后尝试重新加载
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -552,21 +501,19 @@ const getVideoList = async (val) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
hlsRefs.push(player)
|
hlsRefs.push(player)
|
||||||
}else{
|
}
|
||||||
|
else{
|
||||||
const player = new Hls({
|
const player = new Hls({
|
||||||
maxBufferLength: 10, // 最大缓冲长度(秒)
|
maxBufferLength: 10, // 最大缓冲长度(秒)
|
||||||
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
maxMaxBufferLength: 15, // 缓冲区长度的上限
|
||||||
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
|
||||||
})
|
})
|
||||||
player.loadSource(x.hlsUrl)
|
player.loadSource(url)
|
||||||
player.attachMedia(videoElement)
|
player.attachMedia(videoElement)
|
||||||
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
videoElement.play()
|
videoElement.play()
|
||||||
})
|
})
|
||||||
player.on(Hls.Events.ERROR, (event, data) => {
|
player.on(Hls.Events.ERROR, (event, data) => {
|
||||||
// console.error('HLS 播放器遇到错误:', data);
|
|
||||||
// hls.startLoad();
|
|
||||||
// initVideo()
|
|
||||||
// 根据错误类型进行处理
|
// 根据错误类型进行处理
|
||||||
if (data.fatal) {
|
if (data.fatal) {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
@@ -588,6 +535,26 @@ const getVideoList = async (val) => {
|
|||||||
hlsRefs.push(player)
|
hlsRefs.push(player)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
const getVideoList = async (val) => {
|
||||||
|
try {
|
||||||
|
if (loading.value) return
|
||||||
|
loading.value = true
|
||||||
|
if (val == 3) {
|
||||||
|
params.businessVideoDisplayPosition = ''
|
||||||
|
} else {
|
||||||
|
params.businessVideoDisplayPosition = navList.value[current.value]
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = await getVideoListApi(params)
|
||||||
|
total.value = res.total
|
||||||
|
if (res.data.length > 0) {
|
||||||
|
videoList.value = res.data
|
||||||
|
nextTick(() => {
|
||||||
|
videoList.value.forEach(async (x, index) => {
|
||||||
|
const videoElement = document.getElementById(`monitorVideo${index}`)
|
||||||
|
createPlayer(x.cameraIndexCode,videoElement);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (timer) clearInterval(timer)
|
if (timer) clearInterval(timer)
|
||||||
|
|||||||
Reference in New Issue
Block a user