I’m using a video texture in a custom shader. How can I correctly dispose of the video element?
It seems there is no javascript API for this?
Here is my current script
PosteffectNormalVideo.prototype.initialize = function () {
if (this.videoAsset) {
this.videoTexture = new pc.Texture(this.app.graphicsDevice, {
format: pc.PIXELFORMAT_R8_G8_B8,
autoMipmap: false,
flipY: true
});
this.videoTexture.minFilter = pc.FILTER_LINEAR;
this.videoTexture.magFilter = pc.FILTER_LINEAR;
this.videoTexture.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
this.videoTexture.addressV = pc.ADDRESS_CLAMP_TO_EDGE;
let video = document.createElement('video');
video.addEventListener('canplay', () => {
this.videoTexture.setSource(video);
this.entity.script["posteffectNormal"].effect.normalMap = this.videoTexture;
}, { once: true });
video.src = this.videoAsset.getFileUrl();
video.loop = true;
video.muted = true;
video.play();
this.on('destroy', () => {
this.videoTexture.destroy();
video.pause();
video.src = '';
});
}
};
After destroying I can still see the Media in Chrome Dev Tools
Altough I suspect this happens because Chrome Dev Tools never clears this list (even stays visible after navigating).
What bugs me is that there is no
kWebMediaPlayerDestroyed
event called. Which I did see once.