play audio on web on start

This commit is contained in:
2026-11-08 20:52:03 +03:00
parent 5de55fd152
commit 9ffceb91ed
3 changed files with 33 additions and 1 deletions

View File

@@ -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),