pročištění kodu

This commit is contained in:
2021-01-26 23:01:39 +01:00
parent 0ade9c4503
commit 9d8acd5e03
5 changed files with 85 additions and 67 deletions

View File

@@ -2,18 +2,10 @@ class VideoPlayer {
constructor() {
this.video = document.getElementById("video");
this.video.addEventListener(
"loadedmetadata",
function () {
this.init();
}.bind(this)
);
}
// Init
init() {
this.enableCustomControls();
this.addEventListeners();
}
updateVideoDuration() {
this.videoDuration = Math.round(this.video.duration);
const seek = document.getElementById("seek");
@@ -22,36 +14,7 @@ class VideoPlayer {
const progressBar = document.getElementById("progress-bar");
progressBar.setAttribute("max", this.videoDuration);
}
// Přidání listenerů
addEventListeners() {
const videoControls = document.getElementById("video-controls");
const togleButton = document.getElementById("togglePlayIcon");
videoControls.addEventListener(
"click",
function (e) {
if (e.target !== videoControls && e.target !== togleButton) {
return;
}
this.togglePlay();
}.bind(this)
);
this.video.addEventListener(
"timeupdate",
function () {
this.updateProgress();
}.bind(this)
);
this.video.addEventListener(
"ended",
function () {
this.showButton();
}.bind(this)
);
const seek = document.getElementById("seek");
seek.addEventListener("input", this.skipAhead);
}
enableCustomControls() {
const video = document.getElementById("video");
const videoControls = document.getElementById("video-controls");
@@ -109,7 +72,7 @@ class VideoPlayer {
playButton.style.display = "none";
}
}
async getVideoDuration() {
return Math.round(await this.video.duration);
getVideoDuration() {
return Math.round(this.video.duration);
}
}