play audio on web on start
This commit is contained in:
11
shell.html
11
shell.html
@@ -47,6 +47,17 @@
|
||||
<canvas id="canvas" tabindex="-1" oncontextmenu="event.preventDefault()"></canvas>
|
||||
<p>Instructions go here.</p>
|
||||
<script>
|
||||
// Browsers suspend audio until the first user gesture. miniaudio only
|
||||
// installs click/touchend handlers, so make keyboard/pointer input
|
||||
// unlock the audio context too.
|
||||
const unlockEvents = ['keydown', 'pointerdown'];
|
||||
const unlockAudio = () => {
|
||||
if (!window.miniaudio || typeof window.miniaudio.unlock !== 'function') return;
|
||||
window.miniaudio.unlock();
|
||||
unlockEvents.forEach((type) => removeEventListener(type, unlockAudio, true));
|
||||
};
|
||||
unlockEvents.forEach((type) => addEventListener(type, unlockAudio, true));
|
||||
|
||||
var Module = {
|
||||
canvas: document.getElementById('canvas'),
|
||||
print: console.log.bind(console),
|
||||
|
||||
Reference in New Issue
Block a user