-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex.loop.html
52 lines (48 loc) · 1.12 KB
/
ex.loop.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Loop</title>
<style>
button {
color: white;
padding: 10px 20px;
font-size: large;
margin-bottom: 10px;
background: #96729E;
cursor: pointer;
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, .15);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 2px rgba(0, 0, 0, 0.25);
}
button:hover, [role="button"]:hover {
filter: brightness(1.2);
color: white;
}
</style>
</head>
<body>
<button onclick="play()">▶ play</button>
<button onclick="stop()">STOP!!!!</button>
<script>
const audioContext = new AudioContext();
let sample;
function play() {
fetch('Roland-SC-88-Cello-C3-glued-01.wav')
.then(response => response.arrayBuffer())
.then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer))
.then(audioBuffer => {
sample = audioContext.createBufferSource();
sample.buffer = audioBuffer;
sample.loop = true;
sample.connect(audioContext.destination);
sample.start();
})
.catch(e => console.log('uff'));
}
function stop() {
sample.stop();
}
</script>
</body>
</html>