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)