Skip to content

Commit 6736826

Browse files
committed
Try to prime the audio system so that sounds starting after a timer will work
1 parent 012f916 commit 6736826

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/glkote/web/schannels.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@ export class SoundChannelManager extends Map<number, SoundChannel> {
2222
constructor(glkote: WebGlkOte) {
2323
super()
2424
this.glkote = glkote
25-
this.context = new AudioContext()
25+
const context = new AudioContext()
26+
this.context = context
27+
28+
// Try to prime the audio system so that sounds starting after a timer will work
29+
const gain = context.createGain()
30+
const sine_node = context.createOscillator()
31+
gain.gain.value = 0.001
32+
sine_node.frequency.value = 22000
33+
sine_node.connect(gain)
34+
gain.connect(context.destination)
35+
sine_node.start()
36+
setTimeout(() => {
37+
gain.disconnect()
38+
sine_node.stop()
39+
}, 10)
2640
}
2741

2842
async update(schannels: protocol.SoundChannelUpdate[]) {

0 commit comments

Comments
 (0)