fix: await AudioContext.resume() before playing
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user