feat: adaptive bitrate support, engine improvements, demo updates, and electron preload

This commit is contained in:
2026-06-12 17:15:30 +08:00
parent 6575b0be0f
commit b6231e4efd
17 changed files with 139 additions and 4 deletions

View File

@@ -132,9 +132,9 @@ export class Engine {
if (this.isInitialScene) {
this.isInitialScene = false
this.videoManager.playInitial(scene.videoUrl, preloadUrls)
this.videoManager.playInitial(this.videoManager.resolveVideoUrl(scene, this.videoManager.streamingQuality), preloadUrls)
} else {
this.videoManager.switchTo(scene.videoUrl, preloadUrls)
this.videoManager.switchTo(this.videoManager.resolveVideoUrl(scene, this.videoManager.streamingQuality), preloadUrls)
}
}

View File

@@ -12,6 +12,7 @@ export class VideoManager {
private preloaded: Map<'A' | 'B', string> = new Map()
private switching = false
private sceneVideo: HTMLVideoElement | null = null
streamingQuality = ''
private get active(): HTMLVideoElement {
return this.activeSlot === 'A' ? this.elA! : this.elB!
@@ -169,6 +170,30 @@ export class VideoManager {
if (this.elB) this.elB.muted = muted
}
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 key = quality || Object.keys(scene.streamingUrl)[0]
return scene.streamingUrl[key] || scene.videoUrl
}
return scene.videoUrl
}
switchQuality(src: string, seekTime: number) {
const active = this.active
this.currentSrc = src
active.src = src
this.preloaded.set(this.keyOf(active), src)
this.waitReady(active).then(() => {
active.currentTime = seekTime
active.play().catch(() => {})
})
}
private keyOf(el: HTMLVideoElement): 'A' | 'B' {
return el === this.elA ? 'A' : 'B'
}
onEnd(cb: VideoEndCallback) {
this.onEndCallback = cb
}

View File

@@ -21,6 +21,7 @@ export interface SceneNode {
bgmDuckFade?: number
videoMuted?: boolean
skippable?: boolean
streamingUrl?: Record<string, string>
}
export interface Choice {