@@ -3,6 +3,7 @@ import { app } from "electron";
33import { connect } from "net" ;
44import { join } from "path" ;
55import { existsSync , unlinkSync } from "fs" ;
6+ import { fileURLToPath } from "url" ;
67import { processLog } from "../logger" ;
78import mainWindow from "../windows/main-window" ;
89
@@ -129,7 +130,7 @@ export class MpvService {
129130
130131 // 连接成功后再加载文件,确保能收到 file-loaded/playback-restart
131132 if ( url ) {
132- this . sendCommand ( "loadfile" , [ url , "replace" ] ) ;
133+ this . sendCommand ( "loadfile" , [ this . normalizeMpvLoadTarget ( url ) , "replace" ] ) ;
133134 }
134135 } catch ( error ) {
135136 processLog . error ( "启动 MPV 失败:" , error ) ;
@@ -477,4 +478,39 @@ export class MpvService {
477478 this . mpvProcessNonce = null ;
478479 this . pendingFileLoaded = null ;
479480 }
481+
482+ private normalizeMpvLoadTarget ( url ?: string ) {
483+ if ( ! url ) return "" ;
484+ if ( ! url . startsWith ( "file://" ) ) {
485+ return this . normalizeLocalPath ( url ) ;
486+ }
487+
488+ try {
489+ const parsedUrl = new URL ( url ) ;
490+ if ( parsedUrl . host ) {
491+ const uncPath = `//${ parsedUrl . host } ${ decodeURIComponent ( parsedUrl . pathname ) } ` ;
492+ return this . normalizeLocalPath ( uncPath ) ;
493+ }
494+ } catch {
495+ // 忽略 URL 解析失败,继续走兜底逻辑
496+ }
497+
498+ try {
499+ return this . normalizeLocalPath ( fileURLToPath ( url ) ) ;
500+ } catch {
501+ const rawPath = decodeURIComponent ( url . slice ( "file://" . length ) ) ;
502+ return this . normalizeLocalPath ( rawPath ) ;
503+ }
504+ }
505+
506+ private normalizeLocalPath ( filePath : string ) {
507+ if ( process . platform !== "win32" ) return filePath ;
508+ if ( filePath . startsWith ( "//" ) ) {
509+ return filePath . replace ( / \/ / g, "\\" ) ;
510+ }
511+ if ( / ^ [ A - Z a - z ] : \/ / . test ( filePath ) ) {
512+ return filePath . replace ( / \/ / g, "\\" ) ;
513+ }
514+ return filePath ;
515+ }
480516}
0 commit comments