refactor: unify video mode detection into getVideoMode()
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user