fix: add delay after AudioContext resume and schedule offset
This commit is contained in:
@@ -124,6 +124,8 @@
|
||||
const ctx = getAudioContext()
|
||||
if (ctx.state === 'suspended') {
|
||||
await ctx.resume()
|
||||
// Wait a frame for currentTime to update after resume
|
||||
await new Promise(resolve => setTimeout(resolve, 50))
|
||||
}
|
||||
const oscillator = ctx.createOscillator()
|
||||
const gainNode = ctx.createGain()
|
||||
@@ -134,11 +136,13 @@
|
||||
oscillator.frequency.value = frequency
|
||||
oscillator.type = type
|
||||
|
||||
gainNode.gain.setValueAtTime(0.3, ctx.currentTime)
|
||||
gainNode.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + duration)
|
||||
// Use small offset to ensure sound is scheduled in the future
|
||||
const startTime = ctx.currentTime + 0.01
|
||||
gainNode.gain.setValueAtTime(0.3, startTime)
|
||||
gainNode.gain.exponentialRampToValueAtTime(0.01, startTime + duration)
|
||||
|
||||
oscillator.start(ctx.currentTime)
|
||||
oscillator.stop(ctx.currentTime + duration)
|
||||
oscillator.start(startTime)
|
||||
oscillator.stop(startTime + duration)
|
||||
} catch (e) {
|
||||
console.error('Failed to play sound:', e)
|
||||
}
|
||||
@@ -166,7 +170,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleMeetingStarted() {
|
||||
async function handleMeetingStarted() {
|
||||
// Pre-initialize AudioContext on user gesture (meeting start click)
|
||||
// This is required because AudioContext can only be resumed during user interaction
|
||||
const ctx = getAudioContext()
|
||||
if (ctx.state === 'suspended') {
|
||||
await ctx.resume()
|
||||
}
|
||||
meetingActive = true
|
||||
currentView = 'main'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user