Merge pull request #10103 from dataease/pr@dev-v2@refactor_stream

refactor(仪表板、数据大屏): 优化流媒体直播,防止频繁切换直播链接造成无法播放问题
This commit is contained in:
王嘉豪 2024-06-05 11:41:59 +08:00 committed by GitHub
commit dfca84679d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 30 deletions

View File

@ -16,8 +16,8 @@ export const STREAMMEDIALINKS = {
isLive: false,
cors: true, // 允许跨域
loop: true,
autoplay: false
// url: null // 网络动画视频
autoplay: false,
url: null // 网络动画视频
}
}

View File

@ -75,37 +75,30 @@ onMounted(() => {
initOption()
})
watch(
() => element.value.streamMediaLinks,
() => {
destroyPlayer()
nextTick(() => {
state.pOption = element.value.streamMediaLinks[element.value.streamMediaLinks.videoType]
initOption()
})
}
)
const initOption = () => {
if (flvjs.isSupported() && state.pOption.url) {
destroyPlayer()
const video = currentInstance.proxy.$refs['player-' + element.value.id]
if (video) {
try {
state.flvPlayer = flvjs.createPlayer(state.pOption, {
enableWorker: false, // 线
enableStashBuffer: false, // IO
isLive: state.pOption.isLive,
lazyLoad: false
})
state.flvPlayer.attachMediaElement(video)
state.flvPlayer.load()
state.flvPlayer.play()
} catch (error) {
console.error('flvjs err ignore', error)
state.pOption = element.value.streamMediaLinks[element.value.streamMediaLinks.videoType]
delete state.pOption.segments
nextTick(() => {
if (flvjs.isSupported() && state.pOption.url) {
destroyPlayer()
const video = currentInstance.proxy.$refs['player-' + element.value.id]
if (video) {
try {
state.flvPlayer = flvjs.createPlayer(state.pOption, {
enableWorker: false, // 线
enableStashBuffer: false, // IO
isLive: state.pOption.isLive,
lazyLoad: false
})
state.flvPlayer.attachMediaElement(video)
state.flvPlayer.load()
state.flvPlayer.play()
} catch (error) {
console.error('flvjs err ignore', error)
}
}
}
}
})
}
const destroyPlayer = () => {