Fix silent playback on phones

Playback runs through a hidden <audio> element that only had autoplay
set, which mobile browsers ignore for audible media, so it never started.
Call play() on it from a user gesture (any tap/key, and the test tone
button). Also listen for pointerup: on touch screens pointerdown is not a
user activation, so resuming the AudioContext from it alone failed too.

Reported via feedback (Chrome on Android, no voice or test tone) and
reproduced with Firefox on Android.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-22 20:48:34 +00:00
1 parent bcdbabe201
commit be7247f3f6
2 files changed
+16 -2

No files matched your search

+10 -2
View File
@@ -7710,16 +7710,22 @@ function AppInner() {
// Browsers keep an AudioContext created without a user gesture (auto-mic
// on page load, a reconnect) "suspended" - silent - until one happens. The
// mic permission prompt used to be the only thing resuming it, so with the
// mic denied or absent you'd never hear anyone. Any click/keypress does it.
// mic denied or absent you'd never hear anyone. Any click/keypress does it,
// and also starts the player's hidden <audio> element (see unlock()).
useEffect(() => {
const resume = () => {
const ctx = audioContextRef.current;
if (ctx?.state === "suspended") ctx.resume().catch(() => {});
audioPlayerRef.current?.unlock();
};
// pointerup too: on touch screens pointerdown doesn't count as a user
// gesture, so resume()/play() from it alone are refused on phones.
window.addEventListener("pointerdown", resume, true);
window.addEventListener("pointerup", resume, true);
window.addEventListener("keydown", resume, true);
return () => {
window.removeEventListener("pointerdown", resume, true);
window.removeEventListener("pointerup", resume, true);
window.removeEventListener("keydown", resume, true);
};
}, []);
@@ -9554,7 +9560,9 @@ function AppInner() {
};
const handlePlayTestTone = () => {
ensureAudioContext();
const ctx = ensureAudioContext();
if (ctx.state === "suspended") ctx.resume().catch(() => {});
audioPlayerRef.current?.unlock();
audioPlayerRef.current?.playTestTone();
};