From 1f05c2bc4a9ae4791cd64662a5bc8fab98d778f1 Mon Sep 17 00:00:00 2001 From: xinyuaixiaoyu <38575991+xinyuaixiaoyu@users.noreply.github.com> Date: Wed, 8 Nov 2023 10:33:32 +0800 Subject: [PATCH 1/2] Update webaudio.ts stopAT Add function for precise playback --- src/webaudio.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/webaudio.ts b/src/webaudio.ts index 0aa7ff0a1..48af9091d 100644 --- a/src/webaudio.ts +++ b/src/webaudio.ts @@ -100,6 +100,16 @@ class WebAudioPlayer extends EventEmitter { this.emit('pause') } + stopAt(timeSeconds) { + const delay = timeSeconds - this.currentTime + this.bufferNode?.stop(this.audioContext.currentTime + delay) + + this.bufferNode?.addEventListener('ended', () => { + this.bufferNode = null + this.pause() + }, { once: true }) + } + async setSinkId(deviceId: string) { const ac = this.audioContext as AudioContext & { setSinkId: (id: string) => Promise } return ac.setSinkId(deviceId) From eda213429b28821db40d5d4098941ea8d893087d Mon Sep 17 00:00:00 2001 From: xinyuaixiaoyu <38575991+xinyuaixiaoyu@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:15:03 +0800 Subject: [PATCH 2/2] Update webaudio.ts add timeSeconds type --- src/webaudio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webaudio.ts b/src/webaudio.ts index 48af9091d..921fac35f 100644 --- a/src/webaudio.ts +++ b/src/webaudio.ts @@ -100,7 +100,7 @@ class WebAudioPlayer extends EventEmitter { this.emit('pause') } - stopAt(timeSeconds) { + stopAt(timeSeconds: number) { const delay = timeSeconds - this.currentTime this.bufferNode?.stop(this.audioContext.currentTime + delay)