mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 21:31:20 -08:00
feat: 增加字幕相关属性和事件,优化字幕切换逻辑
This commit is contained in:
1 parent
a0b6af32d0
commit
2b11d897ff
11 files changed
+38
-27
No files matched your search
@@ -164,7 +164,6 @@ function artplayerProxyCanvas(callback) {
|
||||
...methods,
|
||||
...prototypes
|
||||
];
|
||||
// 存储 canvas 的原始属性
|
||||
const originalCanvasProperties = {};
|
||||
[
|
||||
"width",
|
||||
@@ -207,8 +206,6 @@ function artplayerProxyCanvas(callback) {
|
||||
}
|
||||
try {
|
||||
if (video.readyState >= 2) {
|
||||
// HAVE_CURRENT_DATA or higher
|
||||
// 使用 createImageBitmap 进行预处理
|
||||
const bitmap = await createImageBitmap(video);
|
||||
ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
||||
bitmap.close();
|
||||
@@ -234,10 +231,8 @@ function artplayerProxyCanvas(callback) {
|
||||
canvasWidth = containerWidth;
|
||||
canvasHeight = canvasWidth / aspectRatio;
|
||||
}
|
||||
// 设置 canvas 大小为实际显示大小
|
||||
canvas.width = canvasWidth;
|
||||
canvas.height = canvasHeight;
|
||||
// 居中 canvas
|
||||
const paddingLeft = (containerWidth - canvasWidth) / 2;
|
||||
const paddingTop = (containerHeight - canvasHeight) / 2;
|
||||
Object.assign(canvas.style, {
|
||||
@@ -247,13 +242,10 @@ function artplayerProxyCanvas(callback) {
|
||||
console.error("Error in resize function:", error);
|
||||
}
|
||||
};
|
||||
// 在视频元数据加载完成后设置 canvas 尺寸并绘制第一帧
|
||||
art.on("video:loadedmetadata", async ()=>{
|
||||
canvas.width = video.videoWidth;
|
||||
canvas.height = video.videoHeight;
|
||||
await sleep(300);
|
||||
resize();
|
||||
drawFrame();
|
||||
});
|
||||
art.on("video:play", ()=>{
|
||||
cancelAnimationFrame(animationFrame);
|
||||
@@ -265,7 +257,6 @@ function artplayerProxyCanvas(callback) {
|
||||
art.on("resize", resize);
|
||||
const destroy = ()=>{
|
||||
cancelAnimationFrame(animationFrame);
|
||||
// 清理其他可能的资源...
|
||||
};
|
||||
art.on("destroy", destroy);
|
||||
if (typeof callback === "function") callback.call(art, video, option.url, art);
|
||||
|
||||
Reference in new issue
Block a user