-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
55 lines (41 loc) · 1.24 KB
/
main.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
import { audioInit, audioUpdate } from './src/audio.js';
import { renderUpdate } from './src/render.js';
function loop() {
let freqData = audioUpdate();
renderUpdate(freqData);
requestAnimationFrame(loop);
}
function init(file) {
console.log("Uploading file");
if (!file) return;
let fileBlob = URL.createObjectURL(file);
document.getElementById("upload").style.display = "none";
audioInit(fileBlob);
requestAnimationFrame(loop);
}
// Uploading the file is the trigger to start
// Drag and Drop upload
document.getElementById("upload").addEventListener("drop", (e) => {
e.preventDefault();
const file = e.dataTransfer.files[0];
init(file);
});
// Manual upload
document.getElementById("file").addEventListener("change", (e) => {
const file = e.target.files[0];
init(file);
});
let fullscreen = false;
const fullscreenButton = document.getElementById("fullscreen-button");
// Fullscreen button
fullscreenButton.addEventListener("click", () => {
if (fullscreen) {
document.exitFullscreen();
fullscreenButton.src = "icons/fullscreen_enter.svg";
fullscreen = false;
} else {
document.documentElement.requestFullscreen();
fullscreenButton.src = "icons/fullscreen_exit.svg";
fullscreen = true;
}
});