phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.3k stars 1.43k forks source link

Removed canvas deletion function due to destroy() #422

Open hate7354 opened 5 months ago

hate7354 commented 5 months ago

When executing player.destroy(), the canvas is destroyed. What should I do because I want to use all functions of destroy() without destroying the canvas?

phoboslab commented 5 months ago

The canvas element is only removed if it was created by JSMpeg in the first place. If you want to keep the canvas, create it outside of JSMpeg and pass it in as an option. E.g.

<canvas id="video-canvas"></canvas>
var element = document.getElementById('video-canvas');
var player = new JSMpeg.Player('file.ts', {canvas: element});

// this will not remove the canvas, since it was not created by jsmpeg
player.destroy();