This commit is contained in:
duanliang
2025-04-17 20:18:38 +08:00
parent d7eeea3efe
commit 09dcabadda
23 changed files with 1302 additions and 269 deletions

View File

@@ -75,7 +75,7 @@
immediate: true
},
url(newUrl) {
console.log(newUrl,'77777777777777777777777777777777')
// console.log(newUrl,'77777777777777777777777777777777')
if (newUrl && this.isActive) {
this.initializePlayer()
}
@@ -162,7 +162,6 @@
if (this.hls) {
this.immediateCleanup()
}
this.hls = new Hls({
// 内存优化配置
maxBufferSize: 0, // 降低缓冲区大小15MB
@@ -200,6 +199,12 @@
this.safePlay()
})
this.hls.on(Hls.Events.ERROR, (event, data) => {
console.log('核心视频错误',data.type)
// this.hls.startLoad(); //重连
if (data.type === Hls.ErrorTypes.BUFFER_STALLED_ERROR) {
console.error('缓冲停滞错误,尝试重新加载视频');
this.hls.startLoad(); // 尝试重新加载视频
}
this.handleHlsError(data)
})
@@ -207,7 +212,31 @@
this.cleanupNetworkResources()
})
},
initVideo() {
this.beforeDestroy()
this.hls = new Hls({
maxBufferLength: 30, // 最大缓冲长度(秒)
maxMaxBufferLength: 15, // 缓冲区长度的上限
maxBufferSize: 30 * 1000 * 1000 // 最大缓冲大小(字节)
})
this.hls.attachMedia(this.video)
this.hls.loadSource(this.url)
// 事件处理
this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
this.loading = false
this.retryCount = 0
this.safePlay()
})
this.hls.on(Hls.Events.ERROR, (event, data) => {
this.hls.startLoad(); //重连
this.handleHlsError(data)
})
this.hls.on(Hls.Events.BUFFER_EOS, () => {
this.cleanupNetworkResources()
})
},
cleanupNetworkResources() {
// 清理已播放的缓冲数据
if (this.hls && this.video) {

View File

@@ -1,11 +1,16 @@
<template>
<div
:id="id"
:style="{
width: styleUtil.px2vw(width),
height: styleUtil.px2vh(height)
}"
/>
<div style="position: relative;">
<div
:id="id"
:style="{
width: styleUtil.px2vw(width),
height: styleUtil.px2vh(height)
}"
/>
<div v-if="condShow==0" class="nYong-du">加载中...</div>
<div v-if="condShow==1" class="nYong-du">暂无数据</div>
</div>
</template>
<script setup>
import styleUtil from '@/utils/styleUtil'
@@ -43,7 +48,7 @@
let timer = null
let currentIndex = -1
let condShow = ref(0)
let params = null
var defaultColors = ['#06E2FF', '#02FFB8', '#FF465F', '#FFCA36', '#9A4BFC', '#044EFF']
const defaultSeriesConfig = (index) => {
@@ -162,14 +167,22 @@
}
setOption(params)
}
let aIndex = 1
watch(
[() => props.data, () => props.xAxisData],
(val) => {
aIndex+=1
if(aIndex>=3&&!val[0].length){
condShow.value = 1
}
if (val[0].length > 0 && val[1].length > 0) {
condShow.value = 2
setTimeout(() => {
init()
}, 1000)
}
}else{
}
},
{ immediate: true }
)
@@ -203,4 +216,17 @@
// timer = undefined
// }
</script>
<style lang="scss"></style>
<style lang="scss">
.nYong-du{
position:absolute;
left:0;
top:0;
width: 100%;
height: 100%;
font-size:vw(18);
color:#999;
display: flex;
align-items: center;
justify-content: center;
}
</style>