优化无人机管理页面的无法切换视频的bug。

This commit is contained in:
wzclm 2025-02-28 15:47:52 +08:00
parent d115627cd0
commit 892f6a04c8

View File

@ -14,17 +14,27 @@ const videoRefs = ref([])
const flvPlayers = ref([]) const flvPlayers = ref([])
// //
const initVideoPlayers = () => { const initVideoPlayers = async () => {
// //
if (mainFlvPlayer.value) { if (mainFlvPlayer.value) {
destroyFlvPlayer(mainFlvPlayer.value) destroyFlvPlayer(mainFlvPlayer.value)
mainFlvPlayer.value = null
} }
flvPlayers.value.forEach(player => destroyFlvPlayer(player))
flvPlayers.value.forEach(player => {
if (player) {
destroyFlvPlayer(player)
}
})
flvPlayers.value = [] flvPlayers.value = []
// DOM
await nextTick()
// //
if (mainVideoRef.value && droneList.value[currentDroneIndex.value]?.status === 'online') { if (mainVideoRef.value && droneList.value[currentDroneIndex.value]?.status === 'online') {
const deviceCode = droneList.value[currentDroneIndex.value].code const deviceCode = droneList.value[currentDroneIndex.value].code
console.log('初始化主视频播放器:', deviceCode)
mainFlvPlayer.value = createFlvPlayer(mainVideoRef.value, deviceCode) mainFlvPlayer.value = createFlvPlayer(mainVideoRef.value, deviceCode)
} }
@ -32,6 +42,7 @@ const initVideoPlayers = () => {
videoRefs.value.forEach((videoRef, index) => { videoRefs.value.forEach((videoRef, index) => {
if (videoRef && droneList.value[index]?.status === 'online') { if (videoRef && droneList.value[index]?.status === 'online') {
const deviceCode = droneList.value[index].code const deviceCode = droneList.value[index].code
console.log('初始化列表视频播放器:', index, deviceCode)
const player = createFlvPlayer(videoRef, deviceCode) const player = createFlvPlayer(videoRef, deviceCode)
flvPlayers.value.push(player) flvPlayers.value.push(player)
} }
@ -87,11 +98,10 @@ const getList = async () => {
} }
// //
const switchMainVideo = (index) => { const switchMainVideo = async (index) => {
if (currentDroneIndex.value === index) return
currentDroneIndex.value = index currentDroneIndex.value = index
nextTick(() => { await initVideoPlayers()
initVideoPlayers()
})
} }
// //