Skip to content

Commit 88f542e

Browse files
committed
Fixed audio resuming in the web version
1 parent 27441ba commit 88f542e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.3.15
44

55
- Organized the FAQ section
6+
- Fixed audio resuming in the web version
67

78
## 2.3.14
89

wasm/pyxel.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function launchPyxel(params) {
4949
let canvas = await _createScreenElements();
5050
let pyodide = await _loadPyodideAndPyxel(canvas);
5151
_hookFileOperations(pyodide, params.root || ".");
52+
_resumeAudioOnInput();
5253
await _waitForInput();
5354
await _executePyxelCommand(pyodide, params);
5455
}
@@ -255,6 +256,18 @@ function _hookFileOperations(pyodide, root) {
255256
};
256257
}
257258

259+
function _resumeAudioOnInput() {
260+
let audioContext = new (window.AudioContext || window.webkitAudioContext)();
261+
let resumeAudio = () => {
262+
if (audioContext.state === "suspended") {
263+
audioContext.resume();
264+
}
265+
};
266+
["keydown", "click", "touchstart"].forEach((event) =>
267+
document.addEventListener(event, resumeAudio)
268+
);
269+
}
270+
258271
function _isTouchDevice() {
259272
return (
260273
"ontouchstart" in window ||

0 commit comments

Comments
 (0)