mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 19:41:25 -08:00
refactor(mediabunny): [PKG-MB-08] checkpoint typed entry and compatible media declarations
This commit is contained in:
1 parent
8a2b56e829
commit
5e28dfee95
39 files changed
+3007
-287
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import type { ProxyOptions, ShimHost } from './engine-types'
|
||||
import type { MenuHost } from './m3u8-types'
|
||||
import type VideoShim from './VideoShim'
|
||||
import { releaseAll } from './cleanup'
|
||||
import { setupM3u8Controls } from './m3u8'
|
||||
|
||||
export interface EntryHost extends ShimHost, MenuHost {
|
||||
constructor: ShimHost['constructor'] & { utils: { createElement: (tag: 'canvas') => HTMLCanvasElement } }
|
||||
option: ShimHost['option'] & { autoSize?: boolean }
|
||||
template?: { $player?: HTMLElement }
|
||||
mediabunny?: unknown
|
||||
}
|
||||
|
||||
export function entryLifecycle(art: EntryHost, canvas: HTMLCanvasElement, shim: VideoShim, option: ProxyOptions) {
|
||||
let closed = false
|
||||
let controls: ReturnType<typeof setupM3u8Controls>
|
||||
function resize(): void {
|
||||
if (closed || !art.template?.$player || art.option.autoSize)
|
||||
return
|
||||
Object.assign(canvas.style, { width: '100%', height: '100%', objectFit: 'contain' })
|
||||
}
|
||||
function destroy(): void {
|
||||
if (closed)
|
||||
return
|
||||
closed = true
|
||||
releaseAll([
|
||||
() => controls?.destroy(),
|
||||
() => {
|
||||
if (art.mediabunny === shim)
|
||||
delete art.mediabunny
|
||||
},
|
||||
() => shim.destroy(),
|
||||
() => art.off?.('resize', resize),
|
||||
() => art.off?.('video:loadedmetadata', resize),
|
||||
() => art.off?.('destroy', destroy),
|
||||
])
|
||||
}
|
||||
function install(): void {
|
||||
art.on('resize', resize)
|
||||
art.on('video:loadedmetadata', resize)
|
||||
controls = setupM3u8Controls({ art, shim, option })
|
||||
art.on('destroy', destroy)
|
||||
}
|
||||
return { install, destroy }
|
||||
}
|
||||
Reference in new issue
Block a user