fix
This commit is contained in:
parent
79eeb9773f
commit
4a38f4daf8
|
|
@ -57,74 +57,17 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||
checkFileAndSetSrc()
|
||||
}, [isOpen, videoPath])
|
||||
|
||||
// 检测是否为Windows绝对路径
|
||||
const isWindowsAbsolutePath = (path: string): boolean => {
|
||||
return /^[A-Z]:\\/i.test(path) || path.includes('\\')
|
||||
}
|
||||
|
||||
// 尝试多种方法加载视频
|
||||
const tryLoadVideo = async (path: string) => {
|
||||
// 根据路径类型选择不同的加载策略
|
||||
const videoPath = path.split('\\').filter(it => it.length > 0).join('/')
|
||||
console.log(`try load video`, videoPath)
|
||||
console.log(`try load video videoPath`, videoPath)
|
||||
const src = convertFileSrc(videoPath)
|
||||
const testResult = await testVideoSource(src, `convertFileSrc`)
|
||||
if (testResult) {
|
||||
console.log(`try load video src`, src)
|
||||
setVideoSrc(src)
|
||||
setLoadingMethod('convertFileSrc')
|
||||
return
|
||||
}
|
||||
setErrorMessage('无法加载视频:所有加载方法都失败了')
|
||||
}
|
||||
|
||||
// 测试视频源是否可用
|
||||
const testVideoSource = (src: string, methodName: string): Promise<boolean> => {
|
||||
return new Promise((resolve) => {
|
||||
const testVideo = document.createElement('video')
|
||||
|
||||
const cleanup = () => {
|
||||
testVideo.removeEventListener('canplay', onCanPlay)
|
||||
testVideo.removeEventListener('error', onError)
|
||||
testVideo.removeEventListener('loadstart', onLoadStart)
|
||||
}
|
||||
|
||||
const onCanPlay = () => {
|
||||
console.log(`${methodName} method successful - video can play`)
|
||||
cleanup()
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
const onError = (e: any) => {
|
||||
console.log(`${methodName} method failed - video error:`, {
|
||||
error: e,
|
||||
networkState: testVideo.networkState,
|
||||
readyState: testVideo.readyState
|
||||
})
|
||||
cleanup()
|
||||
resolve(false)
|
||||
}
|
||||
|
||||
const onLoadStart = () => {
|
||||
console.log(`${methodName} method - load started`)
|
||||
}
|
||||
|
||||
testVideo.addEventListener('canplay', onCanPlay)
|
||||
testVideo.addEventListener('error', onError)
|
||||
testVideo.addEventListener('loadstart', onLoadStart)
|
||||
|
||||
// 设置超时
|
||||
setTimeout(() => {
|
||||
if (testVideo.readyState < 2) { // HAVE_CURRENT_DATA
|
||||
console.log(`${methodName} method timeout`)
|
||||
cleanup()
|
||||
resolve(false)
|
||||
}
|
||||
}, 5000)
|
||||
|
||||
testVideo.src = src
|
||||
testVideo.load()
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const video = videoRef.current
|
||||
|
|
|
|||
Loading…
Reference in New Issue