改为file协议,mac无法播放,试试windows

This commit is contained in:
2025-08-18 10:55:54 +08:00
parent 3ce6c04d66
commit 64184b7a28
4 changed files with 36 additions and 13 deletions

View File

@@ -118,19 +118,31 @@ async function updateVideoSrc() {
const isWindowsPath = /^[a-zA-Z]:[\\/]|^\\/.test(raw)
if (isWindowsPath) {
// Windows: Use Tauri's asset protocol for absolute paths
// Convert backslashes to forward slashes and use asset:// protocol
const normalizedPath = raw.replace(/\\/g, '/')
videoSrc.value = `asset://localhost/${normalizedPath}`
} else {
// Unix-like: Use HTTP protocol for both Tauri and development
const filename = raw.split(/[/\\]/).pop() || "video.mp4";
// Windows: Use file:// protocol for local file access
// Convert backslashes to forward slashes and use file:// protocol
let normalizedPath = raw.replace(/\\/g, '/')
// Use relative HTTP URL for bundled resources
if (filename === 'video.mp4') {
videoSrc.value = '/video.mp4'
// Ensure proper file:// format with drive letter
if (!normalizedPath.startsWith('/')) {
normalizedPath = '/' + normalizedPath
}
// Remove duplicate slashes
normalizedPath = normalizedPath.replace(/\/+/g, '/')
videoSrc.value = `file://${normalizedPath}`
} else {
// Unix-like: Use file:// protocol for absolute paths
if (raw.startsWith('/')) {
videoSrc.value = `file://${raw}`
} else {
videoSrc.value = `/${filename}`
// Use relative HTTP URL for bundled resources
const filename = raw.split(/[/\\]/).pop() || "video.mp4";
if (filename === 'video.mp4') {
videoSrc.value = '/video.mp4'
} else {
videoSrc.value = `/${filename}`
}
}
}

7
src-tauri/Cargo.lock generated
View File

@@ -1576,6 +1576,12 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "httparse"
version = "1.10.1"
@@ -3817,6 +3823,7 @@ dependencies = [
"gtk",
"heck 0.5.0",
"http",
"http-range",
"jni",
"libc",
"log",

View File

@@ -33,7 +33,7 @@ env_logger = "0.11"
[dependencies.tauri]
version = "2.6.2"
features = [
features = [ "protocol-asset",
"tray-icon",
"unstable"
]

View File

@@ -51,7 +51,11 @@
}
],
"security": {
"csp": null
"csp": null,
"assetProtocol": {
"enable": true,
"scope": ["**"]
}
}
}
}