From 466f7c54fbbfa6d7ab9017e3a08c166f5a5f67ab Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 28 Nov 2023 13:21:49 +0100 Subject: [PATCH 1/3] init audioContext at the last moment note that this is too late for the first firework and .init() must be called earlier if the sound for the first firework is to work. --- packages/fireworks-js/src/sound.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/fireworks-js/src/sound.ts b/packages/fireworks-js/src/sound.ts index d0bbf61..035580e 100644 --- a/packages/fireworks-js/src/sound.ts +++ b/packages/fireworks-js/src/sound.ts @@ -49,6 +49,7 @@ export class Sound { } play(): void { + this.init() if (this.isEnabled && this.buffers.length) { const bufferSource = this.audioContext.createBufferSource() const soundBuffer = this.buffers[randomInt(0, this.buffers.length - 1)]! @@ -62,8 +63,6 @@ export class Sound { volume.connect(this.audioContext.destination) bufferSource.connect(volume) bufferSource.start(0) - } else { - this.init() } } } From f7c5ad233d5c0ba8c9577cbe98e2d4d3636c12ff Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 28 Nov 2023 13:27:56 +0100 Subject: [PATCH 2/3] wait until the last minute to initialize sounds --- packages/fireworks-js/src/fireworks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fireworks-js/src/fireworks.ts b/packages/fireworks-js/src/fireworks.ts index 7f52014..8f67815 100644 --- a/packages/fireworks-js/src/fireworks.ts +++ b/packages/fireworks-js/src/fireworks.ts @@ -226,6 +226,7 @@ export class Fireworks { } private initTrace(): void { + this.sound.init(); if (this.waitStopRaf) return const { delay, mouse } = this.opts From ef3f87386eceaf17a4aea396e16f291f3115af35 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 28 Nov 2023 14:08:34 +0100 Subject: [PATCH 3/3] Update sound.ts --- packages/fireworks-js/src/sound.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/fireworks-js/src/sound.ts b/packages/fireworks-js/src/sound.ts index 035580e..c48d935 100644 --- a/packages/fireworks-js/src/sound.ts +++ b/packages/fireworks-js/src/sound.ts @@ -13,7 +13,6 @@ export class Sound { private onInit = false constructor(private readonly options: Options) { - this.init() } private get isEnabled() {