blob: c255bc5414ba41134ae87d948b171c38bd812ac7 (
plain)
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
|
<!DOCTYPE html>
<script>
var ac = new AudioContext();
var runningPromise = new Promise(resolve => {
ac.onstatechange = event => {
if (ac.state == "running") {
resolve();
}
};
});
fetch("audio.ogg").then(response => {
return response.arrayBuffer();
}).then(ab => {
return ac.decodeAudioData(ab);
}).then(ab => {
var src = ac.createBufferSource();
src.buffer = ab;
src.loop = true;
src.loopStart = 0;
src.loopEnd = ab.duration;
src.start();
src.connect(ac.destination);
});
var suspendPromise;
function suspendAC() {
runningPromise.then(() => {
suspendPromise = ac.suspend();
});
}
var resumePromise;
function resumeAC() {
suspendPromise.then(() => {
resumePromise = ac.resume();
});
}
function closeAC() {
resumePromise.then(() => {
ac.close();
});
}
</script>
|