fix:hls传播问题
This commit is contained in:
parent
3d4fa1abb4
commit
7bb632f9a9
@ -286,11 +286,33 @@ const initializePlayer = async (videoUrl?: string) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
player.on('error', (error: any) => {
|
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('错误详情:', {
|
console.error('错误详情:', {
|
||||||
type: error.type,
|
type: error.type,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
url: url
|
url: url,
|
||||||
|
videoError: player?.video?.error,
|
||||||
|
networkState: player?.video?.networkState,
|
||||||
|
readyState: player?.video?.readyState
|
||||||
})
|
})
|
||||||
emit('error', error)
|
emit('error', error)
|
||||||
})
|
})
|
||||||
@ -442,7 +464,8 @@ const switchQuality = (quality: any) => {
|
|||||||
from: getCurrentQualityLabel(),
|
from: getCurrentQualityLabel(),
|
||||||
to: quality.label,
|
to: quality.label,
|
||||||
currentTime: currentTime,
|
currentTime: currentTime,
|
||||||
wasPlaying: wasPlaying
|
wasPlaying: wasPlaying,
|
||||||
|
newUrl: quality.url
|
||||||
})
|
})
|
||||||
|
|
||||||
// 暂停播放
|
// 暂停播放
|
||||||
@ -450,37 +473,30 @@ const switchQuality = (quality: any) => {
|
|||||||
player.pause()
|
player.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换视频源
|
// 销毁当前播放器
|
||||||
if (typeof player.switchVideo === 'function') {
|
if (player) {
|
||||||
player.switchVideo({
|
player.destroy()
|
||||||
url: quality.url,
|
player = null
|
||||||
type: 'auto'
|
}
|
||||||
})
|
|
||||||
|
|
||||||
// 恢复播放状态
|
// 重新初始化播放器使用新的URL
|
||||||
|
initializePlayer(quality.url).then(() => {
|
||||||
|
console.log('✅ 播放器重新初始化完成,新URL:', quality.url)
|
||||||
|
// 恢复播放时间
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (player && player.video) {
|
if (player && player.video) {
|
||||||
player.seek(currentTime)
|
player.seek(currentTime)
|
||||||
if (wasPlaying) {
|
if (wasPlaying) {
|
||||||
player.play()
|
player.play()
|
||||||
}
|
}
|
||||||
|
console.log('✅ 恢复播放状态:', { currentTime, wasPlaying })
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 500)
|
||||||
} else {
|
}).catch(error => {
|
||||||
// 重新初始化播放器
|
console.error('❌ 重新初始化播放器失败:', error)
|
||||||
initializePlayer(quality.url).then(() => {
|
})
|
||||||
// 恢复播放时间
|
|
||||||
setTimeout(() => {
|
|
||||||
if (player && player.video) {
|
|
||||||
player.seek(currentTime)
|
|
||||||
if (wasPlaying) {
|
|
||||||
player.play()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 通知父组件清晰度已切换
|
||||||
emit('qualityChange', quality.value)
|
emit('qualityChange', quality.value)
|
||||||
console.log('✅ 切换清晰度到:', quality.label)
|
console.log('✅ 切换清晰度到:', quality.label)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
@error="onVideoError"
|
@error="onVideoError"
|
||||||
@screenshot="onScreenshot"
|
@screenshot="onScreenshot"
|
||||||
@danmaku-send="onDanmakuSend"
|
@danmaku-send="onDanmakuSend"
|
||||||
|
@qualityChange="onQualityChange"
|
||||||
/>
|
/>
|
||||||
<div v-else class="video-placeholder"
|
<div v-else class="video-placeholder"
|
||||||
:style="{ backgroundImage: course?.coverImage || course?.thumbnail ? `url(${course.coverImage || course.thumbnail})` : '' }">
|
: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 () => {
|
const loadCourseDetail = async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user