feat: 重命名渲染函数,优化绘制逻辑,增加绘制事件的日志输出

This commit is contained in:
Harvey Zack committed 2024-09-14 23:33:30 +08:00
1 parent f867a97032
commit d4a868621f
3 files changed
+15 -13

No files matched your search

@@ -199,20 +199,21 @@ function artplayerProxyCanvas(callback) {
});
}
});
const render = async ()=>{
const draw = async ()=>{
const bitmap = await createImageBitmap(video);
ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
bitmap.close();
art.emit("artplayerProxyCanvas:draw", ctx);
};
const drawFrame = async ()=>{
const animation = async ()=>{
try {
console.log("1");
await render();
await draw();
console.log("2");
} catch (error) {
console.error("Error drawing video frame:", error);
}
animationFrame = requestAnimationFrame(drawFrame);
animationFrame = requestAnimationFrame(animation);
};
const resize = ()=>{
try {
@@ -248,7 +249,7 @@ function artplayerProxyCanvas(callback) {
art.on("video:play", ()=>{
console.log("video:play");
cancelAnimationFrame(animationFrame);
animationFrame = requestAnimationFrame(drawFrame);
animationFrame = requestAnimationFrame(animation);
});
art.on("video:pause", ()=>{
console.log("video:pause");
@@ -256,7 +257,7 @@ function artplayerProxyCanvas(callback) {
});
art.on("resize", ()=>{
resize();
render();
draw();
});
art.on("destroy", ()=>{
cancelAnimationFrame(animationFrame);