summaryrefslogtreecommitdiffstats
path: root/dom/base/test/file_webaudio_startstop.html
blob: c0e4fafb01ae3ac079c5f940807b0e1255414246 (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
<!DOCTYPE html>
<script>
var ac = new AudioContext();
var runningPromise = new Promise(resolve => {
  ac.onstatechange = event => {
    if (ac.state == "running") {
      resolve();
    }
  };
});

var osc = ac.createOscillator();
osc.connect(ac.destination);
osc.start(0);
osc.stop(osc.context.currentTime + 2.0);

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>