Since navigating away from a page with an active AudioContext will close it internally, this patch fixes a similar issue to bug 1180535 for Web Audio too.
41 lines
734 B
HTML
41 lines
734 B
HTML
<!DOCTYPE html>
|
|
<script>
|
|
var ac = new AudioContext();
|
|
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.start();
|
|
src.connect(ac.destination);
|
|
setTimeout(() => {
|
|
if (ac.state == "running") {
|
|
parent.runTest();
|
|
} else {
|
|
setTimeout(arguments.callee, 0);
|
|
}
|
|
});
|
|
});
|
|
|
|
var suspendPromise;
|
|
function suspendAC() {
|
|
suspendPromise = ac.suspend();
|
|
}
|
|
|
|
var resumePromise;
|
|
function resumeAC() {
|
|
suspendPromise.then(() => {
|
|
resumePromise = ac.resume();
|
|
});
|
|
}
|
|
|
|
function closeAC() {
|
|
resumePromise.then(() => {
|
|
ac.close();
|
|
});
|
|
}
|
|
</script>
|