fix:hls传播问题

This commit is contained in:
小张 2025-08-29 18:28:49 +08:00
parent 3d4fa1abb4
commit 7bb632f9a9
2 changed files with 47 additions and 26 deletions

View File

@ -286,11 +286,33 @@ const initializePlayer = async (videoUrl?: string) => {
})
player.on('error', (error: any) => {
console.error('DPlayer 播放错误:', error)
//
const isHarmlessError = (
!error.message || //
error.message === undefined ||
(player && player.video && !player.video.error) //
)
if (isHarmlessError && player && player.video && player.video.readyState > 0) {
console.warn('⚠️ 检测到可能的假阳性错误,但视频仍可播放:', {
type: error.type,
message: error.message,
url: url,
videoReadyState: player.video.readyState,
videoPaused: player.video.paused
})
//
return
}
console.error('❌ DPlayer 播放错误:', error)
console.error('错误详情:', {
type: error.type,
message: error.message,
url: url
url: url,
videoError: player?.video?.error,
networkState: player?.video?.networkState,
readyState: player?.video?.readyState
})
emit('error', error)
})
@ -442,7 +464,8 @@ const switchQuality = (quality: any) => {
from: getCurrentQualityLabel(),
to: quality.label,
currentTime: currentTime,
wasPlaying: wasPlaying
wasPlaying: wasPlaying,
newUrl: quality.url
})
//
@ -450,37 +473,30 @@ const switchQuality = (quality: any) => {
player.pause()
}
//
if (typeof player.switchVideo === 'function') {
player.switchVideo({
url: quality.url,
type: 'auto'
})
//
if (player) {
player.destroy()
player = null
}
//
// 使URL
initializePlayer(quality.url).then(() => {
console.log('✅ 播放器重新初始化完成新URL:', quality.url)
//
setTimeout(() => {
if (player && player.video) {
player.seek(currentTime)
if (wasPlaying) {
player.play()
}
console.log('✅ 恢复播放状态:', { currentTime, wasPlaying })
}
}, 1000)
} else {
//
initializePlayer(quality.url).then(() => {
//
setTimeout(() => {
if (player && player.video) {
player.seek(currentTime)
if (wasPlaying) {
player.play()
}
}
}, 500)
})
}
}, 500)
}).catch(error => {
console.error('❌ 重新初始化播放器失败:', error)
})
//
emit('qualityChange', quality.value)
console.log('✅ 切换清晰度到:', quality.label)
} catch (error) {

View File

@ -75,6 +75,7 @@
@error="onVideoError"
@screenshot="onScreenshot"
@danmaku-send="onDanmakuSend"
@qualityChange="onQualityChange"
/>
<div v-else class="video-placeholder"
:style="{ backgroundImage: course?.coverImage || course?.thumbnail ? `url(${course.coverImage || course.thumbnail})` : '' }">
@ -1451,7 +1452,11 @@ const onDanmakuSend = (text: string) => {
//
}
//
const onQualityChange = (newQuality: string) => {
console.log('🔄 清晰度已切换到:', newQuality)
currentQuality.value = newQuality
}
//
const loadCourseDetail = async () => {