fix: window path

This commit is contained in:
root 2025-07-11 17:05:55 +08:00
parent dae4a24dbc
commit d0c1696f93
1 changed files with 47 additions and 2 deletions

View File

@ -64,11 +64,56 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
name: 'convertFileSrc',
load: () => {
console.log(`convertFileSrc ${path}`)
const src = convertFileSrc(path)
console.log('Trying convertFileSrc:', { originalPath: path, convertedSrc: src })
// 处理Windows路径
let processedPath = path
if (path.includes('\\') && path.includes(':')) {
// Windows绝对路径转换为相对路径或使用不同的处理方式
console.log('Detected Windows absolute path, processing...')
// 尝试移除盘符,使用相对路径
if (path.match(/^[A-Z]:\\/)) {
// 如果是绝对路径,尝试只使用文件名部分或相对路径
const pathParts = path.split('\\')
const fileName = pathParts[pathParts.length - 1]
console.log('Extracted filename:', fileName)
// 先尝试原始路径,如果失败再尝试其他方法
processedPath = path
}
}
const src = convertFileSrc(processedPath)
console.log('Trying convertFileSrc:', {
originalPath: path,
processedPath: processedPath,
convertedSrc: src
})
return src
}
},
{
name: 'windowsPath',
load: async () => {
console.log('Trying Windows path method for:', path)
// 对于Windows路径尝试通过后端API获取文件内容
try {
const fileContent = await invoke<string>('read_file_as_base64', { filePath: path })
const dataUrl = `data:video/mp4;base64,${fileContent}`
console.log('Windows path method successful, data URL length:', dataUrl.length)
return dataUrl
} catch (error) {
console.log('Windows path method failed, trying alternative...')
// 尝试标准化路径
const normalizedPath = path.replace(/\\/g, '/')
const src = convertFileSrc(normalizedPath)
console.log('Trying normalized path:', { normalizedPath, src })
return src
}
}
},
{
name: 'dataUrl',
load: async () => {