-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
81 lines (76 loc) · 2 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
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
// audio source
const audioElA = document.getElementById("audioA");
const audioElB = document.getElementById("audioB");
const master = new AudioContext();
function connect() {
if (audioElA.src == null) {
audio = audioElB;
}
if (audioElB.src == null) {
audio = audioElA;
}
}
// instantiate analyzer
const MainAnalyser = new AudioMotionAnalyzer(
document.getElementById("containerMain"),
{
height: window.innerHeight - 50,
mode: 1,
barSpace: 0.6,
showLeds: true
}
);
const AnalyserA = new AudioMotionAnalyzer(
document.getElementById("containerA"),
{
height: window.innerHeight - 50,
mode: 0,
barSpace: 0.6,
showLeds: true
}
);
const AnalyserB = new AudioMotionAnalyzer(
document.getElementById("containerB"),
{
height: window.innerHeight - 50,
mode: 0,
barSpace: 0.6,
showLeds: true
}
);
// file upload 1
document.getElementById("TrackA").addEventListener("change", (e) => {
let fileBlob = e.target.files[0];
if (fileBlob) {
audioElA.src = "";
AnalyserA.disconnectInput(audioElA);
var filename = $("#TrackA")
.val()
.replace(/.*(\/|\\)/, "");
document.getElementById("Track1Name").innerText = "";
document.getElementById("Track1Name").innerText =
"Current Track: " + filename;
audioElA.src = URL.createObjectURL(fileBlob);
AnalyserA.connectInput(audioElA);
//AnalyserA.connectOutput(master);
audioElA.play();
}
});
// file upload 2
document.getElementById("TrackB").addEventListener("change", (e) => {
let fileBlob = e.target.files[0];
if (fileBlob) {
audioElB.src = "";
AnalyserB.disconnectInput(audioElB);
var filename = $("#TrackB")
.val()
.replace(/.*(\/|\\)/, "");
document.getElementById("Track2Name").innerText = "";
document.getElementById("Track2Name").innerText =
"Current Track: " + filename;
audioElB.src = URL.createObjectURL(fileBlob);
AnalyserB.connectInput(audioElB);
//AnalyserB.connectOutput(master);
audioElB.play();
}
});