fix
This commit is contained in:
parent
79eeb9773f
commit
4a38f4daf8
|
|
@ -57,73 +57,16 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||||
checkFileAndSetSrc()
|
checkFileAndSetSrc()
|
||||||
}, [isOpen, videoPath])
|
}, [isOpen, videoPath])
|
||||||
|
|
||||||
// 检测是否为Windows绝对路径
|
|
||||||
const isWindowsAbsolutePath = (path: string): boolean => {
|
|
||||||
return /^[A-Z]:\\/i.test(path) || path.includes('\\')
|
|
||||||
}
|
|
||||||
|
|
||||||
// 尝试多种方法加载视频
|
// 尝试多种方法加载视频
|
||||||
const tryLoadVideo = async (path: string) => {
|
const tryLoadVideo = async (path: string) => {
|
||||||
// 根据路径类型选择不同的加载策略
|
// 根据路径类型选择不同的加载策略
|
||||||
const videoPath = path.split('\\').filter(it => it.length > 0).join('/')
|
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 src = convertFileSrc(videoPath)
|
||||||
const testResult = await testVideoSource(src, `convertFileSrc`)
|
console.log(`try load video src`, src)
|
||||||
if (testResult) {
|
setVideoSrc(src)
|
||||||
setVideoSrc(src)
|
setLoadingMethod('convertFileSrc')
|
||||||
setLoadingMethod('convertFileSrc')
|
return
|
||||||
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(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue