Files
XCDesktop/remote/public/js/player.js
2026-03-08 01:34:54 +08:00

37 lines
761 B
JavaScript

class VideoPlayer {
constructor(canvasId, wsUrl, options = {}) {
this.canvas = document.getElementById(canvasId);
this.wsUrl = wsUrl;
this.options = {
autoplay: true,
audio: false,
videoBufferSize: 512 * 1024,
...options
};
this.player = null;
}
init() {
this.player = new JSMpeg.Player(this.wsUrl, {
canvas: this.canvas,
...this.options
});
return this;
}
getCanvas() {
return this.canvas;
}
getPlayer() {
return this.player;
}
destroy() {
if (this.player) {
this.player.destroy();
this.player = null;
}
}
}