Simplify video component

This commit is contained in:
Andras Schmelczer 2022-09-25 10:38:44 +02:00
parent aab4cade5e
commit 77a9bcdddf
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
3 changed files with 6 additions and 30 deletions

View file

@ -4,31 +4,15 @@ import { VideoParameters } from './video-parameters';
import { generate } from './video.html';
export class Video extends PageElement {
private video: HTMLVideoElement;
public constructor(options: VideoParameters) {
super(createElement(generate(options)));
this.video = this.query('video') as HTMLVideoElement;
this.htmlRoot.addEventListener('click', this.startVideo.bind(this));
this.query('.start-button').addEventListener('click', this.startVideo.bind(this));
this.video.addEventListener('pause', this.pauseVideo.bind(this));
}
private startVideo() {
if (this.video.paused) {
this.query('.start-button').style.visibility = 'hidden';
this.htmlRoot.classList.add('loaded');
this.video.play();
this.video.controls = true;
}
}
private pauseVideo() {
if (this.video.paused) {
this.query('.start-button').style.visibility = 'visible';
this.video.controls = false;
}
this.query('.start-button').style.visibility = 'hidden';
this.htmlRoot.classList.add('loaded');
(this.query('video') as HTMLVideoElement).play();
}
}