-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
171 lines (140 loc) · 5.37 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const buttonsPlayers = document.querySelectorAll(".btn-play")
const title = document.querySelectorAll("h1")
const subtitle = document.querySelectorAll("h2")
const musicPoster = document.querySelectorAll(".poster img")
const music = document.querySelector("#play-music")
const video = document.querySelector("video")
const videoSource = document.querySelector("source")
const main = document.querySelector("main")
const imageVisibility = document.querySelector(".visibility img")
const timeStart = document.querySelectorAll(".time-start")
const timeEnd = document.querySelectorAll(".time-end")
const buttonPlayPauseVideo = document.querySelector(".btn-play-video")
const progressBars = document.querySelectorAll(".progress")
const buttonSpeedUp = document.querySelectorAll(".btn-next")
const buttonMinimize = document.querySelector("#btn-minimize")
let statusMusic = "paused"
for(let button of buttonsPlayers) {
button.addEventListener("click", () => {
if(statusMusic == "paused") {
playMusicAndVideo("sim")
statusMusic = "playing"
} else {
pauseMusicAndVideo("não")
statusMusic = "paused"
}
})
}
function loopsThroughAllImageElements(element, url) {
let contador = 0
while(contador < element.length) {
element[contador].setAttribute("src", url)
contador++
}
}
function loopsThroughAllTextElements(element, text) {
for(let title of element) {
title.textContent = text
}
}
function showAndHidePlay() {
imageVisibility.addEventListener("click", () => {
main.classList.toggle("hide")
filterVideo()
if(imageVisibility.getAttribute("src") === "./assets/button/visibility_off.svg") {
imageVisibility.setAttribute("src", "./assets/button/visibility.svg")
} else {
imageVisibility.setAttribute("src", "./assets/button/visibility_off.svg")
}
})
}
function showAndHideVideo(value) {
video.style.display = value
}
function changePosterAndTitle(poster, musicTitle, musicSubtitle) {
loopsThroughAllImageElements(musicPoster, `./assets/album/${poster}`)
loopsThroughAllTextElements(title, musicTitle)
loopsThroughAllTextElements(subtitle, musicSubtitle)
}
function playPauseVideo() {
buttonPlayPauseVideo.addEventListener("click", () => {
if(statusMusic == "paused") {
playMusicAndVideo("sim")
statusMusic = "playing"
buttonPlayPauseVideo.setAttribute("src", "./assets/button/pause.svg")
} else {
pauseMusicAndVideo("sim")
statusMusic = "paused"
buttonPlayPauseVideo.setAttribute("src", "./assets/button/play.svg")
changePosterAndTitle("poster-spare-me-great-lord.jpg", "不好惹", "阿萨Aza")
}
})
}
const intervalId = []
function playMusicAndVideo(showVideo) {
buttonPlayPauseVideo.setAttribute("src", "./assets/button/pause.svg")
loopsThroughAllImageElements(buttonsPlayers, "./assets/button/pause.svg")
changePosterAndTitle("poster-spare-me-great-lord.jpg", "不好惹", "阿萨Aza")
if(showVideo === "sim") {
showAndHideVideo("block")
}
music.play()
video.play()
intervalId[0] = setInterval(showMusicTime, 1000)
intervalId[1] = setInterval(showProgress, 1000)
}
function pauseMusicAndVideo(hideVideo) {
buttonPlayPauseVideo.setAttribute("src", "./assets/button/play.svg")
loopsThroughAllImageElements(buttonsPlayers, "./assets/button/play.svg")
loopsThroughAllImageElements(musicPoster, "./assets/album/poster.png")
loopsThroughAllTextElements(title, "Acorda Devinho")
loopsThroughAllTextElements(subtitle, "Banda Rocketseat")
if(hideVideo === "não") {
showAndHideVideo("none")
}
music.pause()
video.pause()
clearInterval(intervalId[0])
clearInterval(intervalId[1])
}
function showProgress() {
const durationMusic = Math.floor(music.duration)
let = timeAtual = Math.floor(music.currentTime)
let percentage = Math.floor((timeAtual / durationMusic) * 100)
for(let element of progressBars) {
element.style.width = `${percentage}%`
}
console.log("Tempo Total: ", durationMusic, " Tempo Atual ", timeAtual, " Porcentagem", percentage)
}
function showMusicTime() {
let minuts = Math.floor(music.currentTime / 60)
let seconds = Math.floor(music.currentTime % 60)
for(let element of timeStart) {
element.textContent = `${String(minuts).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`
}
console.log("minutos ", minuts, " segundos ", seconds)
}
function showMusicDuration() {
const durationMinuts = Math.floor(music.duration / 60)
const durationSeconds = Math.floor(music.duration % 60)
timeEnd[0].textContent = `${durationMinuts}:${durationSeconds}`
timeEnd[1].textContent = `${durationMinuts}:${durationSeconds}`
}
function filterVideo() {
video.classList.toggle("filter-video")
}
function minimizePlayMusic() {
buttonMinimize.addEventListener("click", () => {
main.classList.toggle("minimize")
if(main.className === "minimize") {
buttonMinimize.setAttribute("src", "./assets/button/to-top.svg")
} else {
buttonMinimize.setAttribute("src", "./assets/button/to-bottom.svg")
}
filterVideo()
})
}
showAndHidePlay()
playPauseVideo()
minimizePlayMusic()
window.onload = () => showMusicDuration()