mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
refactor(core): CORE-19 type capture and preserve progress lifetimes
This commit is contained in:
1 parent
98a1800032
commit
ccf77c4ed2
49 files changed
+31570
-681
No files matched your search
@@ -0,0 +1,28 @@
|
||||
export type CaptureMedia = CanvasImageSource & {
|
||||
videoWidth: number
|
||||
videoHeight: number
|
||||
currentTime: number
|
||||
}
|
||||
|
||||
export function drawFrame(canvas: HTMLCanvasElement, video: CaptureMedia): void {
|
||||
canvas.width = video.videoWidth
|
||||
canvas.height = video.videoHeight
|
||||
const context = canvas.getContext('2d')
|
||||
if (!context)
|
||||
throw new TypeError('Canvas 2D context is unavailable')
|
||||
context.drawImage(video, 0, 0)
|
||||
}
|
||||
|
||||
export function captureBlobUrl(canvas: HTMLCanvasElement, resolve: (url: string) => void, reject: (error: unknown) => void): void {
|
||||
canvas.toBlob((blob) => {
|
||||
try {
|
||||
if (!blob)
|
||||
throw new Error('Unable to encode screenshot blob')
|
||||
// The public getBlobUrl caller owns this URL, including after destroy.
|
||||
resolve(URL.createObjectURL(blob))
|
||||
}
|
||||
catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user