-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
77 lines (66 loc) · 2.07 KB
/
renderer.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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
player = document.getElementById("player");
btnPlay = document.getElementById("btnPlay");
btnPause = document.getElementById("btnPause");
btnVolMore = document.getElementById("btnVolMore");
btnVolLess = document.getElementById("btnVolLess");
lblDuration = document.getElementById("lblDuration");
lblSource = document.getElementById("lblSource");
start();
// Salvar dados
function saveData(key, value) {
return localStorage.setItem(key, value);
}
// Salvar dados
function loadData(key) {
return localStorage.getItem(key);
}
// Botão que diminui o volume
btnVolLess.addEventListener("click", function() {
player.volume = player.volume - 0.01;
player.volume < 0.01 ? (player.volume = 0) : player.volume;
saveData("volume", player.volume);
currentVolume();
});
// Botão que aumenta o volume
btnVolMore.addEventListener("click", function() {
player.volume = player.volume + 0.01;
saveData("volume", player.volume);
currentVolume();
});
// Botão que executa a faixa
btnPlay.addEventListener("click", function() {
player.play();
});
// Botão que para a faixa
btnPause.addEventListener("click", function() {
player.pause();
});
// Controla o text do volume
function currentVolume() {
lblVolume.innerText = Math.round(player.volume * 100);
}
// Verifica o tempo corrente da música
function currentTime() {
let date = new Date(0);
date.setSeconds(player.currentTime); // specify value for SECONDS here
lblDuration.innerText = date.toISOString().substr(11, 8);
}
// Função de atualização em tempo real
setInterval(timeExecute, 500);
function timeExecute() {
currentTime();
}
// Configurações executadas ao iniciar
function start() {
parseFloat(loadData("volume"))
? (player.volume = parseFloat(loadData("volume")))
: (player.volume = 0.2);
currentVolume();
currentTime();
}