2022-03-21 00:00:14 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// We will see if the visualizers core and event systems are working correctly.
|
|
|
|
let startBtn = document.getElementById("startbtn");
|
|
|
|
startBtn.addEventListener("click", async (ev) => {
|
|
|
|
let mediaStream = new Audio("../tests/Elektronomia - Collide.mp3");
|
|
|
|
mediaStream.addEventListener("canplaythrough", (ev) => {
|
|
|
|
let visCore = new VisualizerCore(mediaStream, 128);
|
2022-03-21 00:24:22 +00:00
|
|
|
let coreAndEventCanvas = document.getElementById("horizontal");
|
2022-03-21 00:00:14 +00:00
|
|
|
coreAndEventCanvas.width = 640;
|
|
|
|
coreAndEventCanvas.height = 200;
|
|
|
|
|
|
|
|
mediaStream.play();
|
|
|
|
visCore.analyze();
|
|
|
|
|
2022-03-21 00:24:22 +00:00
|
|
|
bindHorizontalBar(coreAndEventCanvas, visCore); // Pre-made simple horizontal bar visualizer.
|
|
|
|
|
|
|
|
let widthDiv = document.getElementById("widthDiv");
|
|
|
|
widthDiv.style.height = "20px";
|
|
|
|
widthDiv.style.backgroundColor = "orange";
|
|
|
|
visCore.addUpdateListener((delta, bins) => {
|
|
|
|
widthDiv.style.width = bins[3] + "px";
|
|
|
|
})
|
|
|
|
|
|
|
|
let colourDiv = document.getElementById("colourDiv");
|
|
|
|
colourDiv.style.height = "20px";
|
|
|
|
visCore.addUpdateListener((delta, bins) => {
|
|
|
|
colourDiv.style.backgroundColor = "rgb(" + bins[0] + "," + bins[1] + ", " + bins[4] + ")";
|
|
|
|
})
|
2022-03-21 00:00:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|