-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
62 lines (54 loc) · 1.94 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const videoPlayer = document.getElementById("videoPlayer");
const playPauseBtn = document.getElementById("playPauseBtn");
const seekSlider = document.getElementById("seekSlider");
const currentTime = document.getElementById("currentTime");
const duration = document.getElementById("duration");
const volumeSlider = document.getElementById("volumeSlider");
const fullscreenBtn = document.getElementById("fullscreenBtn");
const playbackRateSelect = document.getElementById("playbackRateSelect");
playPauseBtn.addEventListener("click", () => {
if (videoPlayer.paused || videoPlayer.ended) {
videoPlayer.play();
playPauseBtn.innerHTML = "❚❚";
} else {
videoPlayer.pause();
playPauseBtn.innerHTML = "►";
}
});
videoPlayer.addEventListener("timeupdate", () => {
const minutes = Math.floor(videoPlayer.currentTime / 60);
const seconds = Math.floor(videoPlayer.currentTime % 60);
currentTime.textContent = `${minutes}:${seconds.toString().padStart(2, "0")}`;
seekSlider.value = videoPlayer.currentTime;
});
videoPlayer.addEventListener("loadedmetadata", () => {
duration.textContent = `${Math.floor(videoPlayer.duration / 60)}:${Math.floor(
videoPlayer.duration % 60
)
.toString()
.padStart(2, "0")}`;
seekSlider.max = videoPlayer.duration;
});
seekSlider.addEventListener("input", () => {
videoPlayer.currentTime = seekSlider.value;
});
volumeSlider.addEventListener("input", () => {
videoPlayer.volume = volumeSlider.value;
});
fullscreenBtn.addEventListener("click", () => {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
videoPlayer.requestFullscreen();
}
});
document.addEventListener("fullscreenchange", () => {
if (document.fullscreenElement) {
fullscreenBtn.innerHTML = "◼";
} else {
fullscreenBtn.innerHTML = "◻";
}
});
playbackRateSelect.addEventListener("change", () => {
videoPlayer.playbackRate = parseFloat(playbackRateSelect.value);
});