mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 12:41:20 -08:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { PlaybackHost } from './engine-ports'
|
|
import type EventTarget from './EventTarget'
|
|
|
|
export function requireDecoder(host: Pick<PlaybackHost, 'audio' | 'video' | 'readyState'>): void {
|
|
// Sinks reflect the decoder's completed capability check; do not query the SDK twice.
|
|
if (host.audio.audioSink || host.video.videoSink)
|
|
return
|
|
host.readyState = 0
|
|
throw new Error('Input has no decodable audio or video tracks.')
|
|
}
|
|
|
|
export function publish(events: EventTarget, current: () => boolean, names: readonly string[]): void {
|
|
for (const name of names) {
|
|
if (!current())
|
|
return
|
|
events.emit(name)
|
|
}
|
|
}
|
|
|
|
export function metadataBarrier(ready: () => void, current: () => boolean) {
|
|
let video = false
|
|
let audio = false
|
|
let published = false
|
|
function complete(part: 'audio' | 'video'): void {
|
|
if (!current() || published)
|
|
return
|
|
if (part === 'video')
|
|
video = true
|
|
else audio = true
|
|
if (video && audio) {
|
|
published = true
|
|
ready()
|
|
}
|
|
}
|
|
return { video: () => complete('video'), audio: () => complete('audio') }
|
|
}
|