mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 19:41:25 -08:00
refactor(mediabunny): [PKG-MB-05] own video iterators, frame pools and rendering
This commit is contained in:
1 parent
5d0b128483
commit
9d037dcbf9
27 files changed
+3652
-595
No files matched your search
@@ -0,0 +1,33 @@
|
||||
export default class Poster {
|
||||
private image: HTMLImageElement | null = null
|
||||
|
||||
cancel(): void {
|
||||
if (!this.image)
|
||||
return
|
||||
this.image.onload = null
|
||||
this.image.onerror = null
|
||||
this.image = null
|
||||
}
|
||||
|
||||
draw(source: string, current: () => boolean, draw: (image: HTMLImageElement) => void, failure: (error: unknown) => void): void {
|
||||
this.cancel()
|
||||
const image = new Image()
|
||||
this.image = image
|
||||
image.onload = () => {
|
||||
if (this.image !== image || !current())
|
||||
return
|
||||
this.cancel()
|
||||
try {
|
||||
draw(image)
|
||||
}
|
||||
catch (error) {
|
||||
failure(error)
|
||||
}
|
||||
}
|
||||
image.onerror = () => {
|
||||
if (this.image === image)
|
||||
this.cancel()
|
||||
}
|
||||
image.src = source
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user