37 lines
761 B
JavaScript
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;
|
|
}
|
|
}
|
|
}
|