-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path03_hello_webcam.js
More file actions
40 lines (36 loc) · 1 KB
/
03_hello_webcam.js
File metadata and controls
40 lines (36 loc) · 1 KB
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
var soundPaths = [
'chords/a_major_7th.mp3',
'chords/b_major_7th.mp3',
'chords/c_sharp_minor_7th.mp3',
'chords/e_major_7th.mp3',
'chords/a_major_short.mp3',
'chords/b_major_short.mp3',
'chords/c_sharp_minor_short.mp3',
'chords/e_major_short.mp3',
];
var soundBlobUrls = [];
var loadAudioDataBuffer = function (path) {
return fetch(path)
.then(function (request) {
console.log('what is request?', request);
return request.blob();
})
.then(function (blob) {
return URL.createObjectURL(blob);
});
};
var soundBlobUrlPromises = soundPaths.map(loadAudioDataBuffer);
Promise.all(soundBlobUrlPromises).then(function (allTheLoadedThings) {
console.log('WHat is allTheLoadedThings', allTheLoadedThings);
soundBlobUrls = allTheLoadedThings;
});
var playSound = function (soundPath) {
var audio = new Audio();
audio.src = soundPath;
audio.play();
};
var collideWithCircle = function(config) {
var index = config.index;
playSound(soundBlobUrls[index % soundBlobUrls.length]);
};
vsyncLoop();