mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 20:21:20 -08:00
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import type Artplayer from 'artplayer'
|
|
import type { ProxyOptions } from './engine-types'
|
|
import type { EntryHost } from './entry-lifecycle'
|
|
import { bridgeCanvas } from './canvas-bridge'
|
|
import { entryLifecycle } from './entry-lifecycle'
|
|
import VideoShim from './VideoShim'
|
|
|
|
export default function artplayerProxyMediabunny(option: ProxyOptions = {}) {
|
|
return (player: Artplayer): HTMLCanvasElement => {
|
|
// Runtime constructor utilities and the owned alias exceed the historical consumer facade.
|
|
const art = player as unknown as EntryHost
|
|
const { createElement } = art.constructor.utils
|
|
const canvas = createElement('canvas')
|
|
const shim = new VideoShim({ art, canvas, ctx: canvas.getContext('2d'), option })
|
|
const lifecycle = entryLifecycle(art, canvas, shim, option)
|
|
try {
|
|
art.mediabunny = shim
|
|
bridgeCanvas(canvas, shim)
|
|
lifecycle.install()
|
|
}
|
|
catch (error) {
|
|
try {
|
|
lifecycle.destroy()
|
|
}
|
|
catch (failure) { console.warn('MediaBunny entry setup cleanup:', failure) }
|
|
throw error
|
|
}
|
|
return canvas
|
|
}
|
|
}
|
|
|
|
// Restore the 1.0.0 CommonJS namespace path without changing the callable factory type.
|
|
Object.defineProperty(artplayerProxyMediabunny, 'default', { value: artplayerProxyMediabunny, writable: true, configurable: true })
|