fix: await AudioContext.resume() before playing

This commit is contained in:
Mikhail Kiselev
2026-02-10 16:45:56 +03:00
parent 649b1c039d
commit 906f504d49
2 changed files with 4 additions and 4 deletions

View File

@@ -119,11 +119,11 @@
return audioContext return audioContext
} }
function playBeep(frequency, duration, type = 'sine') { async function playBeep(frequency, duration, type = 'sine') {
try { try {
const ctx = getAudioContext() const ctx = getAudioContext()
if (ctx.state === 'suspended') { if (ctx.state === 'suspended') {
ctx.resume() await ctx.resume()
} }
const oscillator = ctx.createOscillator() const oscillator = ctx.createOscillator()
const gainNode = ctx.createGain() const gainNode = ctx.createGain()

View File

@@ -40,12 +40,12 @@
return audioContext return audioContext
} }
function playBeep(frequency, duration, type = 'sine') { async function playBeep(frequency, duration, type = 'sine') {
try { try {
const ctx = getAudioContext() const ctx = getAudioContext()
// Resume context if suspended (required by browsers on first interaction) // Resume context if suspended (required by browsers on first interaction)
if (ctx.state === 'suspended') { if (ctx.state === 'suspended') {
ctx.resume() await ctx.resume()
} }
const oscillator = ctx.createOscillator() const oscillator = ctx.createOscillator()
const gainNode = ctx.createGain() const gainNode = ctx.createGain()