Replies: 1 comment
-
你这样可以吗。我销毁后再次播放pag就会内存泄漏,页面卡死。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
只用了pagFile和pagView,还要去销毁PAGComposition吗?销毁之后,PAGInit的PAG可以重复使用吗?
`if (!this.PAG) {
const { PAGInit } = await import("libpag");
this.PAG = await PAGInit();
}
const blob = await fetch(pagUrl).then((response) => response.blob());
const file = new window.File([blob], pagUrl.replace(/(./)([^.]+)/i, "$2"));
const pagFile = await this.PAG.PAGFile.load(file);
// 宽高的缩放比例
this.canvasDom.width = this.screenWidth;
this.canvasDom.height = pagFile.height() / (pagFile.width() / this.screenWidth);
const pagView = await this.PAG.PAGView.init(pagFile, this.canvasDom, { firstFrame: false });
pagView.setRepeatCount(1);
await pagView.play();
this.pagView = pagView;
this.pagFile = pagFile;
pagView.addListener("onAnimationEnd", async () => {
await this.destroy();
this.$emit("onAnimationEnd");
});
async destroy() {
// 销毁图片
if (this.pagFile) {
this.pagFile.destroy();
this.pagFile = null;
}
if (this.pagView) {
if (this.pagView?.pagSurface) {
await this.pagView.pagSurface.clearAll();
}
await this.pagView?.destroy();
this.pagView = null;
}
}`
Beta Was this translation helpful? Give feedback.
All reactions