2015-07-06 02:44:28 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<script>
|
|
|
|
var ac = new AudioContext();
|
2015-09-29 16:57:01 +03:00
|
|
|
var runningPromise = new Promise(resolve => {
|
|
|
|
ac.onstatechange = event => {
|
|
|
|
if (ac.state == "running") {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2015-07-06 02:44:28 +03:00
|
|
|
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;
|
2015-08-16 01:43:20 +03:00
|
|
|
src.loopStart = 0;
|
|
|
|
src.loopEnd = ab.duration;
|
2015-07-06 02:44:28 +03:00
|
|
|
src.start();
|
|
|
|
src.connect(ac.destination);
|
|
|
|
});
|
|
|
|
|
|
|
|
var suspendPromise;
|
|
|
|
function suspendAC() {
|
2015-09-29 16:57:01 +03:00
|
|
|
runningPromise.then(() => {
|
|
|
|
suspendPromise = ac.suspend();
|
|
|
|
});
|
2015-07-06 02:44:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var resumePromise;
|
|
|
|
function resumeAC() {
|
|
|
|
suspendPromise.then(() => {
|
|
|
|
resumePromise = ac.resume();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeAC() {
|
|
|
|
resumePromise.then(() => {
|
|
|
|
ac.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|