refactor: unify video mode detection into getVideoMode()

This commit is contained in:
2026-06-12 19:10:51 +08:00
parent 32f7e34130
commit 8655e01c23
3 changed files with 133 additions and 3 deletions

View File

@@ -1,6 +1,15 @@
type VideoEndCallback = () => void
type TimeUpdateCallback = (time: number) => void
export function getVideoMode(): 'auto' | 'local' | 'streaming' {
const params = typeof URLSearchParams !== 'undefined' ? new URLSearchParams(location.search) : { get: () => null }
const override = params.get('videoMode')
if (override === 'local') return 'local'
if (override === 'streaming') return 'streaming'
if (typeof window !== 'undefined' && (window as any).__ELECTRON__) return 'local'
return 'auto'
}
export class VideoManager {
private elA: HTMLVideoElement | null = null
private elB: HTMLVideoElement | null = null
@@ -171,8 +180,9 @@ export class VideoManager {
}
resolveVideoUrl(scene: { videoUrl: string; streamingUrl?: Record<string, string> }, quality?: string): string {
const isElectron = typeof window !== 'undefined' && !!(window as any).__ELECTRON__
if (!isElectron && scene.streamingUrl) {
const mode = getVideoMode()
if (mode === 'local') return scene.videoUrl
if (scene.streamingUrl) {
const key = quality || Object.keys(scene.streamingUrl)[0]
return scene.streamingUrl[key] || scene.videoUrl
}